title: php - save username as variable then echo it elsewhere
body: <p>I'm trying to modify a login form for a forum so that after logging in, it'll go, "Welcome, username."</p>
  
  <p>Here's a chunk of the signin.php contents -</p>
  
  <pre><code>    if($errors == false){
  
      $user = $db-&gt;get_row("SELECT * FROM " . TABLES_PREFIX . "users WHERE email = '" . $_POST['username_or_email'] . "'  OR username = '" . $_POST['username_or_email'] . "' ORDER BY id DESC LIMIT 0,1");
  
      if($user AND ($user-&gt;password == encode_password($_POST['password']))){
          if($user-&gt;status == 'pending'){
              $layout-&gt;AddContentById('alert', $layout-&gt;GetContent('alert'));
              $layout-&gt;AddContentById('alert_nature', ' alert-danger');
              $layout-&gt;AddContentById('alert_heading', '{{ST:error}}!');
              $layout-&gt;AddContentById('alert_message', '{{ST:your_account_not_activated}}');
          }elseif($user-&gt;status == 'banned'){
              $layout-&gt;AddContentById('alert', $layout-&gt;GetContent('alert'));
              $layout-&gt;AddContentById('alert_nature', ' alert-danger');
              $layout-&gt;AddContentById('alert_heading', '{{ST:error}}!');
              $layout-&gt;AddContentById('alert_message', '{{ST:your_account_is_banned}}');
          }else{
              Users_LoggedIn($user, isset($_POST['remember_me']));
  
              // **I'm guessing this is exactly where I should store the username as var**
  
              header('Location: '.FORUM_URL); // redirects to index.php
              exit;
          }
      }else{
          $layout-&gt;AddContentById('alert', $layout-&gt;GetContent('alert'));
          $layout-&gt;AddContentById('alert_nature', ' alert-danger');
          $layout-&gt;AddContentById('alert_heading', '{{ST:error}}!');
          $layout-&gt;AddContentById('alert_message', '{{ST:the_info_is_not_correct}}');
      }
  }
  </code></pre>
  
  <p>And, then in index.php I guess I would add a line that goes something like (pseudo-code) -</p>
  
  <pre><code>echo '&lt;div id="username"&gt;Welcome, '+$USERNAME+'&lt;/div&gt;';
  </code></pre>
  
  <p>I've tried playing around with $_SESSION['username'] but I'm pretty useless in php, so any guidance would be very helpful, thanks.</p>