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

后端 未结 6 1568
刺人心
刺人心 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:20

    could the code after the header-location call be effectively executed?

    Yes, always. The header is only a line of data asking the browser to redirect. The rest of the page will still be served by PHP and can be looked at by the client by simply preventing the header command from executing.

    That is easy enough to do with a command-line client like wget, for example, by simply telling it not to follow redirects.

    Bottom line: If you don't prevent it, PHP will send out the whole body even after a header call. That body is fully available to the recipient without any special hacking skills.

提交回复
热议问题