title: How do I pass the username variable to a third php page?
body: <ol>
  <li>A user logs on using any username and password (index.php)</li>
  <li>The form goes for processing in at "login.php"</li>
  <li>Once logged on, the "login.php" directs the user to "friends.php"</li>
  </ol>
  
  <p>I want to display on the friends.php page, the <strong>exact username</strong> the user entered when he/she initially logged in using the index script.</p>
  
  <p>I tried using sessions and $_POST, but to no success. Please help! </p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>&lt;html&gt;
  
  
      &lt;body&gt;
              Username: &lt;input type = "text" name = "username"&gt;&lt;br&gt;
              Password: &lt;input type = "password" name = "pass_word"&gt;&lt;br&gt;
              &lt;input type = "submit" value = "Login"&gt; 
          &lt;/form&gt;
  
      &lt;/body&gt;
  
  &lt;/html&gt;
  
  &lt;?php
  
      session_start();
  
      if (isset($_POST['login'])) {
          $_SESSION['username'] = $_POST['username'];
      }
  
  ?&gt;
  </code></pre>
  
  <p><strong>login.php</strong></p>
  
  <pre><code>&lt;?php
  
      session_start();
  
      if(isset($_SESSION['loggedin']) == true) {
          header("Location: friends.php");
  
      }
  
  ?&gt;
  </code></pre>
  
  <p><strong>friends.php</strong></p>
  
  <pre><code>&lt;?php
  
      session_start();
  
      echo $_POST['username'];
  
  ?&gt;
  </code></pre>