Why, if it is important to forward a user, use exit ()?

header('Location: http://smowhere.com '); exit(); 

    2 answers 2

    This is important because redirection is usually used in case of an impossible / unauthorized action, i.e.

     if (!$user->is_logged()) { header('Location: /login'); exit; //иногда в фреймворках $app->finish(); } echo "Hello {$user->name}!"; 

    if you just have a redirect page (why I don’t need it), then of course exit; not required.

      To stop the execution of the current script. For example, you have this code:

       header('Location: http://google.com '); unlink('test.txt'); 

      In this case, the second line will be executed and the test.txt file will be deleted. If this is not desirable, then we naturally write this:

       header('Location: http://google.com '); exit; unlink('test.txt');