title: PHP login script redirection not working after login
body: <p>I found and fixed a little bit I am not so good with PHP but any improvements are welcome.</p>
  
  <p>The problem is that sometimes in Chrome and Opera but only sometimes after login sucess the script redirect to a welcome page with javascript redirection after 5 secs. But sometimes it just get stuck and does not redirect but just show a white page without error and other times it redirect and worls fine. What can it be?</p>
  
  <p>Here is the code</p>
  
  <pre><code>&lt;?php session_start();?&gt;
  &lt;?php
  include 'inc/connection.php';
  $db=mysqli_connect($dbserver, $dbuser, $dbpass, $dbname)or die("DB connection error...");
  
  $username_to_sanitize = $_POST['username'];
  $password_to_sanitize = $_POST['password'];
  $sanitized_username = mysqli_real_escape_string($db, $username_to_sanitize);
  $sanitized_password = mysqli_real_escape_string($db, $password_to_sanitize);
  
  $query = "SELECT password, salt, privilege, username FROM members WHERE username = '$sanitize_username'";
  $result = mysqli_query($db, $query);
  if(mysqli_num_rows($result) == 0) // User not found. Redirected to login page.
  {header('Location:login.php?message=Username not found, please try again');}
  
  $userData = mysqli_fetch_array($result, MYSQL_ASSOC);
  $hash = hash('sha256', $userData['salt'] . hash('sha256', $sanitized_password) );
  
  if($hash != $userData['password']) // Incorrect passw. Redirected to login page.
  {header('Location:error.php?message=Wrong password, please try again');}
  
  else if($userData['privilege']=="ADMIN"){session_start();
  $_SESSION['username']=$userData['username'];
  header('Location:redirection.php?URL=admins/index.php');}
  
  else if($userData['privilege']=="MODERATOR"){session_start();
  $_SESSION['username']=$userData['username'];
  header('Location:redirection.php?URL=moderators/index.php');}
  
  else if($userData['privilege']=="MEMBER"){session_start();
  $_SESSION['username']=$userData['username'];
  header('Location:redirection.php?URL=members/index.php');}
  
  else if($userData['privilegio']=="BANNED"){session_start();
  $_SESSION['username']=$userData['username'];
  header('Location:redirection.php?URL=banned/index.php');}
  
  else{
  header('Location:error.php?message=su need privileges to acces this site');
  exit();
  }
  ?&gt;
  </code></pre>
  
  <p>After reading and testing new scripts found on internet I still cannot fix this problem after 2 months. Any idea?</p>