Why I have to call 'exit' after redirection through header('Location..') in PHP?

后端 未结 6 1620
刺人心
刺人心 2020-11-22 10:38

You know that if you want to redirect an user in PHP you can use the header function:

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

It is also

6条回答
  •  春和景丽
    2020-11-22 11:29

    If you redirect but you don't die() / exit() the code is always executed and displayed.

    Take the following example:

    admin.php:

    if (authenticationFails)
    {
        // redirect and don't die
    }
    
    // show admin stuff
    

    If you don't make sure to end the execution after the location header every user will gain access.

提交回复
热议问题