php - Get username from $_SESSION -


i trying username of users echo out seeing userid or if try echo username gives me string length rather actual name.

i calling in session script header included on pages:

    <? session_start(); session_regenerate_id(); $_session['username']=$email;  include ('../db_con.php'); ?> 

within header.php file want echo out username not mentioned above when try show length , not actual name:

            <?php echo $_session['username'];              var_dump($_session);         ?> 

the session begins login script here:

<? session_start(); if(isset($_session['user'])){     header("location:home.php");     exit; }       $dbh=new pdo('mysql:dbname=dashboardr;host=localhost', '******', '******');/*change credentials connect database.*/     $email=$_post['username'];     $password=$_post['pass'];      if(isset($_post) && $email!='' && $password!=''){         $sql=$dbh->prepare("select id,password,psalt user_login username=?");         $sql->execute(array($email));      while($r=$sql->fetch()){         $p=$r['password'];         $p_salt=$r['psalt'];         $id=$r['id'];     }          $site_salt="subinsblogsalt"; /*common salt used password storing on site. can't change it. if want change it, change when register user.*/         $salted_hash = hash('sha256',$password.$site_salt.$p_salt);      if($p==$salted_hash){         $_session['user']=$id;   $_session['username']=$email;          header("location:home.php");      }else{         echo "<h2>username/password incorrect.</h2>";         }     } ?> 

the reason not see user name in:

$_session['username']

is because never put there.

you need assign user name session so:

$_session['username']=$email;

you can echo $_session['username']; ever want username displayed.

make sure on page use sessions have session_start(); before output.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -