Yes, this question has been asked before, however, the answers have been inconsistent. Take Why I have to call 'exit' after redirection through header('Location..') in PHP? for instance. Every answer (including the accepted answer) states yes, except the last answer which received zero votes which says "maybe". I am starting to think the correct answer is "maybe". To make it a simple "yes" or "no" question, will doThis() be executed given the following script? Thanks
header('Location: http://somewhereElse.com'); //die(); sleep(1000); doThis();
EDIT Thanks, all. With my PHP/Linux/Apache configuration, the second syslog() executes, so the answer is "yes, all script down stream of the header will be executed." I will assume (and hope I am correct) it is the same with all PHP/Linux/Apache configurations!
<?php header('Location: http://google.com'); syslog(LOG_INFO,'first'); sleep(5); syslog(LOG_INFO,'Second'); ?>
You definitely should. Otherwise the script execution is not terminated. Setting another header alone is not enough to redirect. exit always interrupts the current script (in your case "fileA").
Redirection in PHP can be done using the header() function. To setup, a simple redirect simply creates an index. php file in the directory you wish to redirect from with the following content: <?
The header() function in PHP sends a raw HTTP header to a client or browser. Before HTML, XML, JSON, or other output is given to a browser or client, the server sends raw data as header information with the request (particularly HTTP Request).
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:
<?php header('Location: http://google.com'); error_log("WE MADE IT HERE SOMEHOW"); ?>
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
Possibly surprising, but yes, it continues to execute if you don't halt execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With