header information

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
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

header information

Post by duk »

hy guys,

i need to update a cookie when is necessary but the problem is using the function setcookie(); i got problems of Cannot modify header information - headers already sent by...

my question is how can we modify a cookie when is necessary and avoiding this problem ??

thanks in advance
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

don't output -- echo -- anything until after all processing has been completed.
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

well i have some html output... just before a echo you say ???
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

whats your page codes?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have you searched this community for your error message? This question has been asked like 10 times in the last two weeks. :?

You are getting the error message because you are outputting something to the browser before your call to set_cookie. The same goes for the use of the header() function and session_start(). Make sure do not send any output to the browser at all (not even a single blank space) before your call to set_cookie.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

if you for some reason you aren't able to do this, use the following before ANY other code executes:

Code: Select all

ob_start();
then after the set_cookie() call, run:

Code: Select all

echo ob_get_clean();
Post Reply