title: How can I display a user's username after successful php login?
body: <p>So I cannot seem to get this to work following other peoples answers. So I have my files set up like this:</p>
  
  <ul>
  <li>Index</li>
  <li>Register</li>
  <li>Config</li>
  <li>Home</li>
  <li>Logout</li>
  </ul>
  
  <p><em>config.php</em></p>
  
  <pre><code>&lt;?php
  // These variables define the connection information for your MySQL database
  $username = "XXX";
  $password = "XXX";
  $host = "XXX";
  $dbname = "XXX";
  
  $options = array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; 'SET NAMES utf8');
  try { 
      $db = new PDO("mysql:host={$host}; dbname={$dbname}; charset=utf8",
                     $username, $password, $options);
  } catch (PDOException $ex){
      die("Failed to connect to the database: " . $ex-&gt;getMessage());
  }
  
  $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $db-&gt;setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  header('Content-Type: text/html; charset=utf-8');
  session_start();
  ?&gt;
  </code></pre>
  
  <p>And in my <code>home.php</code>, which is the page it will redirect you to after a successful login I want it to show the username, like, "Hello, {username}"... However I am having some trouble achieving this.</p>
  
  <p><em>home.php</em> were I want the username to show:</p>
  
  <pre><code>&lt;ul class="nav navbar-nav navbar-right"&gt;
      &lt;li class="divider-vertical"&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;Hello, {USERNAME HERE!!}&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="logout.php"&gt;Log Out&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Where '{USERNAME HERE!!}' would be some php code that would allow the username to be shown there.</p>
  
  <p>I just cannot for the life of me figure out how to get it to show the username of the person who signed up.</p>