Should'nt the following give an error message? It sends me to domain.com/asdad/
instead of giving me an error message.
<?php
echo 'asdadasdasd';
if ($_SERVER['REQUEST_URI'] == '/newtest.php') {
header("Location: /asdad/");
exit;
}
?>
I view this directly, no other files开发者_Python百科 or code before or after this. Should'nt header
give me an error and NOT send me to the new page as I have output before the header
?
Check your phpinfo()
, you probably have output_buffering
switched on.
PHP output, like most IO, is often put into a temporary buffer until a critical amount is reached (or a user calls flush
), at which point the contents are flushed to the browser. If you manage to send a header
before the output buffer is flushed, you can get away with it.
However, this is not something you rely on, as the buffer size (or, indeed, buffering at all) can vary between installations.
精彩评论