note 27816 added to function.headers-sent

From: Date: Thu, 19 Dec 2002 19:39:53 +0000
Subject: note 27816 added to function.headers-sent
Groups: php.notes 
Request: Send a blank email to php-notes+get-41129@lists.php.net to get a copy of this message
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"; } ?> -- http://www.php.net/manual/en/function.headers-sent.php http://master.php.net/manage/user-notes.php?action=edit+27816 http://master.php.net/manage/user-notes.php?action=delete+27816 http://master.php.net/manage/user-notes.php?action=reject+27816

« previous php.notes (#41129) next »