PHP : Headers Already Sent ??

twister

Howdy
Hello-

I'm having an issue with PHP. Everything was working fine until i tried to set a cookie. Now when i set a cookie php always says "Cannot add header information - headers already sent in header.php"

Well the only other PHP code i have on this page is two includes, one for header.php and one for footer.php, and some more after the cookie information.

header.php also has a simple if statement in it, which in this case is returning false and nothing is happening.

Now if i remove the header include, the error still happens and my cookie won't get set. Any clue on what could be wrong? I've decided it hates my cookie as it never gets set.

Another, related question, is how can i save a bunch of information for later use without using a cookie? I was sending it via post except this time i cant. Kinda hard to explain. And if i use GET the URL would be REALLY long and then not safe from tampering with the values. So i've heard about Globals but I don't know how to use them.

If anyone can help that'd be great.
 
i'm not sure about your cookie problem, but as far as storing vars for later use, use a session variable. there is some good info on the php.net web site.

hope it helps.
 
as for your header problem, i think i read once somewhere that that will happen if there is blank space before the opening php tag. something about php already trying to send output to the browser.


sorry i couldnt be more help.
 
I've had this before and it's a case of quitting the browser and flushing out the cache.

It's like the browser gets all snarled up on the cookie stuff.

Could be that, or I could be utterly wrong!..
 
That's a common error when any HTML output (even a blank space) is sent before certain PHP calls like session and header functions. I think it can also happen if your code starts with PHP code and has spaces before the first <? on the page.
 
note: for COOKIE and SESSION.

- these 2 must be sent before any output from your script (this is protocol restriction) including <html> and <head> tags as well as any whitespace.
 
Back
Top