do I need to use exit after header(“Location: http://localhost/…”);?

后端 未结 6 1225
清酒与你
清酒与你 2021-02-19 02:53

I\'m creating a script to validate a form and I was asking myself a question. When I use a header (see example below), do I need to use exit right after? I mean, does using head

6条回答
  •  天命终不由人
    2021-02-19 03:19

    You should call exit() because a header() won't automatically stop the script from executing - or if it does (I'm honestly not 100% on that), it definitely doesn't stop the script instantly.

    For example, try this code:

    
    

    This little script uses header() to redirect you to Google, and then deletes itself. If you run it, you'll notice that after you were redirected, the file was still deleted. This means that the unlink() call was still executed even though the header() call redirected you.

提交回复
热议问题