title: Login redirecting to specific page based on user name
body: <p>I'm in the process of learning PHP and MySQL.</p>
  
  <p>I would like from the script to recognize a specific name and redirect it to admin.php. For example "if Username is Brian redirect him to admin.php, if the username is everything except Brian, redirect him to account.php".</p>
  
  <p>Both Brian and the other persons must be registered in the database to be able to login. I thought on redirect based on MySQL user id, but I don't know how to write the code. Or if you know another simple solution.</p>
  
  <p>Here is the script:</p>
  
  <pre><code>&lt;?php
  
   class Users {
       public $username = null;
       public $password = null;
       public $salt = "";
  
       public function __construct( $data = array() ) {
           if( isset( $data['username'] ) ) $this-&gt;username = stripslashes( strip_tags( $data['username'] ) );
           if( isset( $data['password'] ) ) $this-&gt;password = stripslashes( strip_tags( $data['password'] ) );
       }
  
       public function storeFormValues( $params ) {
          //store the parameters
          $this-&gt;__construct( $params ); 
       }
  
       public function userLogin() {
           $success = false;
           try{
              $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); 
              $con-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
              $sql = "SELECT userID FROM users WHERE username='username'  AND password= :password AND userTypeId = 1 LIMIT 1";
  
          $stmt = $con-&gt;prepare( $sql );
              $stmt-&gt;bindValue( "username", $this-&gt;username, PDO::PARAM_STR );
              $stmt-&gt;bindValue( "password", hash("sha256", $this-&gt;password . $this-&gt;salt), PDO::PARAM_STR );
              $stmt-&gt;execute();
  
              $valid = $stmt-&gt;fetchColumn();
  
              if( $valid ) {
                  $success = true;
              }
  
              $con = null;
              return $success;
           }catch (PDOException $e) {
               echo $e-&gt;getMessage();
               return $success;
           }
       }
  </code></pre>
  
  <p>And this is the script from index.php (where the user writes his name and password)</p>
  
  <pre><code>&lt;?php 
  } else {
      $usr = new Users;
      $usr-&gt;storeFormValues( $_POST );
  
      if( $usr-&gt;userLogin() ) {
          echo "Welcome"; 
      } else {
          echo "Incorrect Username/Password"; 
      }
  }
  
  ?&gt;
  </code></pre>