On Monday, December 22, 2003, at 01:13 PM, Website Managers.net wrote:

Unless you're using an 'if' statement, the header redirect must be the first line of the page, above any HTML markup.

That's not entirely accurate.


---Quoted from http://php.net/header ---
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. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
----------------------------------------


header() doesn't need to be 'the first line of the page', but it does need to be placed above/before any output gets sent to the browser.

bad:
<html>
<? header(...); ?>

bad:
<?
echo "foo";
header(...);
?>

good:
<?
include('something.inc');
session_start();
$foo = 'bah';
header(...);
?>

if there's any code following the redirect (which you don't want to execute), I'd also strongly recommend having an exit; after the header():

<?
include('something.inc');
if($foo)
        {
        header(...);
        exit;
        }
// some other stuff that shouldn't get executed after redirect
?>


Justin French


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to