title: Get username from $_SESSION
body: <p>I am trying to get the username of my users to echo out but only seeing the userID or if I try to echo the username it gives me the string length rather than the actual name.</p>
  
  <p>I am calling in my session script into my header which is included on all pages:</p>
  
  <pre><code>    &lt;?
  session_start();
  session_regenerate_id();
  $_SESSION['username']=$email;
   include ('../db_con.php');
  ?&gt;
  </code></pre>
  
  <p>within the header.php file I want to echo out the username but not as mentioned above when I try that it show the length and not the actual name:</p>
  
  <pre><code>            &lt;?php echo $_SESSION['username']; 
              var_dump($_SESSION);
          ?&gt;
  </code></pre>
  
  <p>the session begins from my login script here:</p>
  
  <pre><code>&lt;?
  session_start();
  if(isset($_SESSION['user'])){
      header("Location:home.php");
      exit;
  }
  
  
      $dbh=new PDO('mysql:dbname=dashboardr;host=localhost', '******', '******');/*Change The Credentials to connect to database.*/
      $email=$_POST['username'];
      $password=$_POST['pass'];
  
      if(isset($_POST) &amp;&amp; $email!='' &amp;&amp; $password!=''){
          $sql=$dbh-&gt;prepare("SELECT id,password,psalt FROM user_login WHERE username=?");
          $sql-&gt;execute(array($email));
  
      while($r=$sql-&gt;fetch()){
          $p=$r['password'];
          $p_salt=$r['psalt'];
          $id=$r['id'];
      }
  
          $site_salt="subinsblogsalt"; /*Common Salt used for password storing on site. You can't change it. If you want to change it, change it when you register a 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 "&lt;h2&gt;Username/Password is Incorrect.&lt;/h2&gt;";
          }
      }
  ?&gt;
  </code></pre>