Search code examples
phpauthenticationprogram-entry-point

How to redirect the user to their proper pages after login?


I want to redirect the user to their proper main page. I also want to keep the sessions that I have know in my login.php. In my users table I store the username, password and type.

login.php

<?php

require ('connect.php');
if (isset($_POST['submit'])) {

$username = $_POST['username'];
$password = $_POST['password'];


if ($username && $password) {
    $check = mysql_query("SELECT * FROM users WHERE username='".$username."' AND password= '".$password."'");
    $rows = mysql_num_rows($check);


    if(mysql_num_rows($check) != 0){

      session_start();
      $run_login =mysql_fetch_array($check);
      $uid = $run_login['id'];
      $_SESSION['uid'] = ['uid'];
      $_SESSION['username']=$_POST['username'];
      header("location:../../statistics/home.php");

    }
    else{
      die("Could not find the Username or password.");
   }
}
 else {
     echo "Please fill all the fields.";
 }
}
?>

Solution

  • put die(); after header("location:../../statistics/home.php"); and check session in home.php