Page 1 of 1
Cannot modify header information - headers already sent...
Posted: Mon Mar 07, 2005 3:32 pm
by Jr
Ok, I'm sure SOMEone has run into this problem somewhere using PHP right? I'm trying to set cookies but it keeps giving me an error of:
Cannot modify header information - headers already sent...
...for each cookie that is trying to be set. I know I can't "print" or "include" anything before the cookies are set but I need to check to check the user_name / password against the database before i set the cookies. Is there a way around this without needing server/php.ini file access?
If I could figure out how to send PHP variables in a Javascript/HTML URL that would fix my problem too. Does anyone know how to do that?
Thanks,
Jr
Posted: Mon Mar 07, 2005 3:53 pm
by timvw
offcourse we have answered this questions many times before too.....
search young paduan

Posted: Mon Mar 07, 2005 4:10 pm
by Burrito
look at the ob_ functions
specifically you might check out ob_start()
Posted: Mon Mar 07, 2005 5:12 pm
by feyd
no, do not use output buffering. That's the bandaid approach to fixing the issue. We have a tutorial on why it happens and how to go about fixing it.
Posted: Mon Mar 07, 2005 5:53 pm
by Jr
um... ok... I appriciate the help but where's the tutorial?
Posted: Mon Mar 07, 2005 6:51 pm
by feyd
Try the "Tutorials" board

Posted: Mon Mar 07, 2005 7:04 pm
by Jr
hehe... I would guess that the tutorial is in the "tutorials" section but what is it called? Can you post up a link?
Thanks,
Jr-
Posted: Mon Mar 07, 2005 7:13 pm
by feyd
Posted: Tue Mar 08, 2005 11:00 am
by Jr
OK!... I have TRIED and TRIED and TRIED to figure out how to fix this problem and have gone around in circles about a million times.
- I can't send a PHP header() redirect after I check for user authentication
- I can use a JavaScript redirect but i cant send php variables in the URL with it
- and i obviously cant setcookies() in a function after authentication even though there is nothing print""ed or include""d before it in the function
- I have looked up using OutputBuffering but NONE of the tutorials make sense to where I can get that to work
- And i really dont know where to go from here!!!
Does ANYone know the "best" way to do this that isn't just a "band-aid" fix? I would GREATLY appriciate it if someone could help, this has been killing me for the longest time.
Posted: Tue Mar 08, 2005 3:54 pm
by Jr
Ok, my bad...

I didnt realize that I forgot to "print" the PHP variable when I used it in the JavaScript redirect (didn't read down that far in the tutorial). I DIDN'T however use the Output Buffering like the tutorial said. I just used a redirect paget that gets variables and then passes them back to an IF statement (at the top of the page) that actually sets the cookies.
Thanks for the help guys.
Much Appriciated,
Jr-