title: Passing php variable from this.php to that.php
body: <p>So I need to pass a variable from one php to another php page but I dont know how to do it. I got this piece of code "$realname= $row['name'];" that stores the real name of the person to display it in another page after they successfully login, but when I try to use $realname variable in the other page it wont display it. How can I make this posible??? thanks in advance</p>
  
  <p>page one login.php</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" href="style.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
  
  include 'functions.php';
  
  if(loggedin())
  {
  header("Location: userarea.php");
  exit();
  }
  
  if(isset($_POST['login']))
  {
  //get data
  $username = $_POST['username'];
  $password = $_POST['password'];
  $rememberme = $_POST['rememberme'];
  
      //validate
      if($username&amp;&amp;$password)
      {
          $login = mysql_query("SELECT * FROM users WHERE username='$username'");
          if(mysql_num_rows($login) == 1)
          {
              while($row = mysql_fetch_assoc($login))
              {
  
                  $db_password = $row['password'];
                  if($password == $db_password)
                     $loginok= TRUE;
                  else
                     $loginok = FALSE;
  
                   if($loginok==TRUE)
                   { 
  
                                    $realname= $row['name'];
  
                                         if($rememberme == "on")
                          setcookie("username", $username, time() + 7200);
                      else if ($rememberme == "")
                          $_SESSION['username'] = $username;
  
  
                      header("Location: userarea.php");
                      exit();
                   }
                   else
                       die("Incorrect username or password. Please try again or contact your local admin.");
              }
  
          }die("Incorrect username or password. Please try again or contact your local admin.gdfgdfgdfg");
      }
      else
          die("Please enter a username and password.");
  
  }
  
  ?&gt;
  
  
  &lt;h&gt;Welcome!&lt;/h&gt;
  
      &lt;form action="login.php" method="POST"&gt;
  
      Username:&lt;br /&gt; 
      &lt;input type="text" name="username"&gt;&lt;p /&gt;
  
      Password:&lt;br /&gt; 
      &lt;input type="password" name="password"&gt;&lt;p /  &gt;  
  
  
  
      &lt;input type="checkbox" name="rememberme"&gt; Remember me&lt;br /&gt;
  
      &lt;input type="submit" name="login" value="Log in"&gt;
  
      &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>Page 2 userarea.php (as you can see I declared $realname variable but I cant use it)</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;?php
  
  include 'functions.php';
  
  
  if(!loggedin())
  {
  header("Location: login.php");
  exit();
  
  }
  
  echo "Hello $realname";
  
  ?&gt;
  
  
  
  &lt;h&gt;Access Granted! Yeiy! &lt;/h&gt;
  &lt;a href="logout.php"&gt; Log out &lt;/a&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>