Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 795

PHP header in if statement not redirecting user

$
0
0

I am currently working on a login page on which I want the user to be redirected to another page if a Boolean read from the database is set to true.However, the header() in this if statement never redirects the user properly.

here is a sample of my code:

<?phpsession_start();include_once 'php/dbconnect.php';//check if form is submittedif (isset($_POST['login'])) {    $gebruikersnaam = mysqli_real_escape_string($con, $_POST['username']);    $password = mysqli_real_escape_string($con, $_POST['password']);    $result = mysqli_query($con, "SELECT * FROM users WHERE username = '" . $gebruikersnaam. "' and password = '" . md5($password) . "'");    if ($row = mysqli_fetch_array($result)) {        $_SESSION['usr_id'] = $row['id'];      if($row['initialised'] == true)      {        header("Location: dashboard.php");        exit();      }      else{        $_SESSION['usr_name'] = $row['username'];        $_SESSION['usr_company'] = $row['companyname'];        header("Location: starter-page.php");        exit();      }      } else {        $errormsg = "Incorrect Email or Password!";     }}?>

If I put the if condition on false. The second header with "location: strater-page.php" will redirect to the correct page.

I do not have any unnecessary whitespace.

Putting:

error_reporting(E_ALL);ini_set('display_errors', 1); 

In the code doesn't show anything.I am not outputting anything before the header...Am I missing something?


Viewing all articles
Browse latest Browse all 795

Trending Articles