Cannot modify header information - headers already sent...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Cannot modify header information - headers already sent...

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

offcourse we have answered this questions many times before too.....

search young paduan :)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

look at the ob_ functions

specifically you might check out ob_start()
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

um... ok... I appriciate the help but where's the tutorial?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Try the "Tutorials" board :)
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post 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-
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post 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.
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

Ok, my bad... :oops: 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-
Post Reply