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

后端 未结 6 1223
清酒与你
清酒与你 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:22

    It does NOT stop your script from running, your script will keep on running and sometimes all a person (could be with bad intentions) needs is your script to reach a certain point where he could do X. Header() will just redirect, exit(); however will stop the script right on the spot (where exit(); is). or as someone else stated under the username:

    Cody. A. Ray: Yes, the script continues to process after the call to header('Location: http://google.com') if you don't explicitly terminate it! I just tried this locally. I added test.php to a site in apache with these contents

    
    

    And checked my /var/log/apache2/error_log for this entry:

     [Tue Feb 12 23:39:23 2013] [error] [client 127.0.0.1] WE MADE IT HERE SOMEHOW
    

    so end conclusion: Header doesn't stop the script from running.

提交回复
热议问题