note 27816 deleted from function.headers-sent by nlopess
| From: | nlopess@php.net | Date: | Tue, 16 Dec 2003 15:22:41 +0000 |
| Subject: | note 27816 deleted from function.headers-sent by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62067@lists.php.net to get a copy of this message | ||
Note Submitter: php@compeng.net
----
Who cares if headers have been sent: we just want to get to another web page: How about the
following.
Does this make header( "Location: ... obsolete? comments on this are encouraged.
<?php
// If no headers are sent, send one
if (!headers_sent()) {
header ('Location: http://www.example.com/');
exit;
}
// An example using the optional file and line parameters, as of PHP 4.3.0
// Note that $filename and $linenum are passed in for later use.
// Do not assign them values beforehand.
if (!headers_sent($filename, $linenum)) {
header ('Location: http://www.example.com/');
exit;
// Use refresh if header does not work. This seems to work in the middle of
// any web page. I am not sure what it will do to the browser, though.
} else {
echo "\n<meta http-equiv=\"refresh\" "
. " content=\"0;URL=http://www.example.com\">\n";
}
?>