View Full Version : headers already sent
im really not understanding this
when I try to use header("Location: index.php") for example I get an error saying that the headers have already been sent.
I have no idea where the error could be but to be honest i'm still trying to figure out the whole headers thing.
The header function is only used once in the entire script..but I am using sessions..is there possibly a clash or what the hey is causing this error msg?
putts
12-23-2005, 01:17 PM
get these from time to time......
check to make sure you don't have an include file that's sending that particular header already or any sort of loop that might contain that statement.
AaronCampbell
12-23-2005, 03:48 PM
Actually, you can send LOTS of headers with the header command, but they MUST occur before ANY output. You can't send the <html> or anything at all (even a blank line) to the user before you send a header. So, this is right:<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: http://{$_SERVER['HTTP_HOST']}/index.php");
?>But this is wrong (and will give you that error):<html>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: http://{$_SERVER['HTTP_HOST']}/index.php");
?>
elecktricity
12-23-2005, 04:00 PM
all headers like the one your using must be at the top, its like defines if its a html page, gif image or what not, your wanting it to redirect to another page, so it shouldnt load other stuff before it sends you over, get what im saying?
Gamini
12-24-2005, 03:45 AM
You can also use the output buffer.
This will store all the output, and only send it once all the processing has finished, therefore the header function will work even if content has been output before it.
http://www.php.net/outcontrol Has a lot of useful information on this.
aahhh ok its making a lot more sense thanx for the help :)
yes it working now I had echo'd a bunch of html before sending the headers..with a bit of script re-structuring it is working no prob now ;)
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.