Why, if it is important to forward a user, use exit ()?
header('Location: http://smowhere.com '); exit();
Why, if it is important to forward a user, use exit ()?
header('Location: http://smowhere.com '); exit();
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');
Source: https://ru.stackoverflow.com/questions/208354/
All Articles