mysql - Displaying username on index.php -
mysql table contains following rows: id
, user_name
, name
, password
. on login form require user submit name
, password
, on submitting same direct user index.php
page. after user login wish display value of "user_name" contains user full name, on top of index.php
page.
for example
hello : user_name.
how it?
there many different ways (using session,cookies,localstorage etc). i'll show simple way using session;
let's on top of page want have container displaying name, example :
<div class='greet'> hello <?php echo $_session['username']; ?> </header>
what want show if user logged :
<?php if(isset($_session['username']): ?> <div class='greet'> hello <?php echo $_session['username']; ?> </header> <?php endif; ?>
so now, if user logged, div created.
when user trying log in (i'm guessing posting username , password php file , searching results in table), if login successful have add 1 line of code there this:
if(login success condition here){ //some code $_session['username'] = $username; }
now can use variable $_session['username'] display username anywhere wish.
Comments
Post a Comment