I'm using PHP 7.1.11 on a machine that runs on Windows 10 Home Single Language edition.
I'm using XAMPP server on my machine.
I'm using following browsers on this machine :
- Google Chrome(Version 62.0.3202.94 (Official Build) (64-bit))
- Firefox Quantum(57.0.1 (64-bit))
- Opera(Version : 49.0.2725.47)
- Microsoft Edge 41.16299.15.0
I know the details of header()
function and how it works.
But following program is behaving in really a weird way on all of the above four web browsers. Even after sending output to the client the header() function is working.
How can this be possible?
Below is my code(It's getting redirected to the URL I mentioned) :
<!DOCTYPE html>
<html>
<body>
<p>Welcome to my website!</p><br />
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if($test) {
echo 'Welcome to my website<br />You\'re in!';
} else {
header('Location: http://www.espncricinfo.com');
}
?>
</body>
</html>
I was expecting to get the warning 'Cannot modify header information - headers already sent by' but surprisingly it's getting redirected me to the URL http://www.espncricinfo.com/
?
Why?