Re: newbie question about header()

From: Date: Mon, 22 Dec 2003 02:05:18 +0000
Subject: Re: newbie question about header()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-173123@lists.php.net to get a copy of this message
Scott Taylor wrote:
I am simply trying to redirect users from one page to another. Yet when I use this code I get the following error: *Warning*: Cannot add header information - headers already sent by (output started at /usr/local/psa/home/vhosts/miningstocks.com/httpdocs/etc/php/login/admin/test.php:8) in */usr/local/psa/home/vhosts/miningstocks.com/httpdocs/etc/php/login/admin/test.php* on line *9* * * <html> <head> </head> <body> <?php header('Location: http://www.slashdot.org/'); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?>
You can't have any output before trying to use header(). <html>, etc, are considered output. So, the very first line in your file must be <?php and you can use header() before you echo anything within that PHP block. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#173123) next »