<?php
header("Location: secondone.html");
exit();
die();
?>
Ah, the header() function redirects the page to a new page.
Therefore, the exit and die do not ever execute. This code just switches to the secondone.html page.
And, you would not put a DIE after and EXIT as it will never get to the DIE line. Exit stops processing that script. Hope that helps.
Not entirely true.
They are executed even if not needed.
The header redirect is performed by the client.
The server is just sending the header like every other header and continues script execution normally. It isn’t aware of any redirect. It’s just sending data to the client.
Everything else you said however is correct.
The header command happens in the server since it is a PHP command.
It never happens in the broswer, the client. NO PHP is ever executed in any browser.
I am not sure who told you that but, you are 100% incorrect.
ALL PHP commands are executed before anything is ever sent to the browser.
Therefore, it will never get to the other commands.
The header function is executed on the server.
But it does nothing but sending the header to the client.
The client upon receiving the header follows the redirect (or not). The decision to follow the redirect in a new request is a 100% client action.
The server cannot enforce any client action.
Thus it continues to run the script.
You can easily verify that by adding some simple file put contents after the header command before the exist command. You will observe the following:
- a normal browser will follow the redirect
- the server however still will write that file
Also it is not true that all php is executed before anything is send to the client.
Just take a look at ob_flush for example.
And please don’t shout at me, if you have no idea what you are actually talking about.
I’m out since you seem to be quite resistant to learn anything.