title: How to direct different users to different pages after login?
body: <p>I created a database (following an online tutorial) which directs all users to one login page. I was wondering how can I direct different users to different webpages. For example I want to direct JOHN SMITH (user1) to localhost/pages/johnsmith.html and JANE SMITH (user 2) to localhost/pages/janesmith.html.</p>
  
  <p>Code: </p>
  
  <p>db_const.php</p>
  
  <pre><code>&lt;?php
  # mysql db constants DB_HOST, DB_USER, DB_PASS, DB_NAME
  const DB_HOST = 'localhost';
  const DB_USER = 'root';
  const DB_PASS = 'root';
  const DB_NAME = 'ClientDashboard';
  ?&gt;
  </code></pre>
  
  <p>login.php</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;User Login Form - PHP MySQL Ligin System | W3Epic.com&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
   &lt;h1&gt;User Login Form - PHP MySQL Ligin System | W3Epic.com&lt;/h1&gt;
   &lt;?php
    if (!isset($_POST['submit'])){
  
  
   ?&gt;
  &lt;!-- The HTML login form --&gt;
  &lt;form action="&lt;?=$_SERVER['PHP_SELF']?&gt;" method="post"&gt;
      Username: &lt;input type="text" name="username" /&gt;&lt;br /&gt;
      Password: &lt;input type="password" name="password" /&gt;&lt;br /&gt;
  
      &lt;input type="submit" name="submit" value="Login" /&gt;
  &lt;/form&gt;
  &lt;?php
    } else {
  require_once("db_const.php");
  $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  # check connection
  if ($mysqli-&gt;connect_errno) {
      echo "&lt;p&gt;MySQL error no {$mysqli-&gt;connect_errno} : {$mysqli-&gt;connect_error}&lt;/p&gt;";
      exit();
  }
  
  
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  $sql = "SELECT * from users WHERE username LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
  $result = $mysqli-&gt;query($sql);
  if (!$result-&gt;num_rows == 1) {
      echo "&lt;p&gt;Invalid username/password combination&lt;/p&gt;";
  } else {
      echo "&lt;p&gt;Logged in successfully&lt;/p&gt;";
      // do stuffs
  }
  }
  ?&gt;      
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>register.php </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
     &lt;title&gt;User registration form- PHP MySQL Ligin System | W3Epic.com&lt;/title&gt;
  &lt;/head&gt;
   &lt;body&gt; 
    &lt;h1&gt;User registration form- PHP MySQL Ligin System | W3Epic.com&lt;/h1&gt;
   &lt;?php
  require_once("db_const.php");
  if (!isset($_POST['submit'])) {
  ?&gt;  &lt;!-- The HTML registration form --&gt;
  &lt;form action="&lt;?=$_SERVER['PHP_SELF']?&gt;" method="post"&gt;
      Username: &lt;input type="text" name="username" /&gt;&lt;br /&gt;
      Password: &lt;input type="password" name="password" /&gt;&lt;br /&gt;
      First name: &lt;input type="text" name="first_name" /&gt;&lt;br /&gt;
      Last name: &lt;input type="text" name="last_name" /&gt;&lt;br /&gt;
      Email: &lt;input type="type" name="email" /&gt;&lt;br /&gt;
  
      &lt;input type="submit" name="submit" value="Register" /&gt;
  &lt;/form&gt;
  &lt;?php
  } else {
  ## connect mysql server
  $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  # check connection
  if ($mysqli-&gt;connect_errno) {
      echo "&lt;p&gt;MySQL error no {$mysqli-&gt;connect_errno} : {$mysqli-   &gt;connect_error}&lt;/p&gt;";
      exit();
  }
   ## query database
  # prepare data for insertion
  $username   = $_POST['username'];
  $password   = $_POST['password'];
  $first_name = $_POST['first_name'];
  $last_name  = $_POST['last_name'];
  $email      = $_POST['email'];
  
  # check if username and email exist else insert
  $exists = 0;
  $result = $mysqli-&gt;query("SELECT username from users WHERE username =   '{$username}' LIMIT 1");
  if ($result-&gt;num_rows == 1) {
      $exists = 1;
      $result = $mysqli-&gt;query("SELECT email from users WHERE email =   '{$email}' LIMIT 1");
      if ($result-&gt;num_rows == 1) $exists = 2;    
  } else {
      $result = $mysqli-&gt;query("SELECT email from users WHERE email = '{$email}' LIMIT 1");
      if ($result-&gt;num_rows == 1) $exists = 3;
  }
  
  if ($exists == 1) echo "&lt;p&gt;Username already exists!&lt;/p&gt;";
  else if ($exists == 2) echo "&lt;p&gt;Username and Email already exists!  &lt;/p&gt;";
  else if ($exists == 3) echo "&lt;p&gt;Email already exists!&lt;/p&gt;";
  else {
      # insert data into mysql database
      $sql = "INSERT  INTO `users` (`id`, `username`, `password`, `first_name`, `last_name`, `email`) 
              VALUES (NULL, '{$username}', '{$password}', '{$first_name}', '{$last_name}', '{$email}')";
  
      if ($mysqli-&gt;query($sql)) {
          //echo "New Record has id ".$mysqli-&gt;insert_id;
          echo "&lt;p&gt;Registred successfully!&lt;/p&gt;";
      } else {
          echo "&lt;p&gt;MySQL error no {$mysqli-&gt;errno} : {$mysqli-&gt;error}  &lt;/p&gt;";
          exit();
          }
      }
   }
  ?&gt;      
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thanks!</p>