phpauthenticationhttp-redirect

Why is the page still loading after an redirect?


I have an strange problem which I can't find out what is causing this behaviour.

I have an page called dashboard.php where I have this code:

mail('xxx@gmail.com', 'Dashboard 1', 'isLoggedin = ' . $isLoggedIn);

if(!$isLoggedIn) {
  header("Location: https://example.com/account/login.php");
}

mail('xxx@gmail.com', 'Dashboard 2', 'Dashboard 2');

If the user isn't logged on the dasboard.php page, he must be redirected to the login.php page.

When I am not logged in and go to dashboard.php, the following happened:

  1. I got the first mail where isLoggedin is empty (which is correct ofcourse)
  2. I got redirected to the login.php page which is also correct
  3. I got the second 'Dashboard 2' mail which I don't understand.

Why get I the second mail but I am redirected to the login.php so the script in dashboard.php shouldn't get so far? Why is the script after the redirect still running?


Solution

  • as shown in php.net docs, you have to exit; your script, otherwise it will be executed.