Php Doc Says:
"Remember that
header()
must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from
PHP."" This requires that you place calls to
setcookie()
prior to any output, including and tags as well as any whitespace."
I understand the importance of above mentioned requirements but how is the code below running without throwing "Headers already Sent"
error?
<html>
<body>
<h1>Hey</h1>
<?php
echo "Hello";
setcookie("hey","hellocookie");
//header("Pragma: no-cache");
//echo $_COOKIE['hey'];
header('Location: http://www.example.com/');
?>
</body>
</html>
header('Location: http://www.example.com/');
works without throwing errors. Also,setcookie("hey","hellocookie");
works even though there's an outputecho "Hello";
prior to it. I tested it withecho $_COOKIE['hey'];
and it does printheycookie
.
*Note: Running the above script on Localhost/Xampp. Error Reporting is not disabled. I do get an error on browser output if I miss one of those semi-colons. *