By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

Error:"Cannot modify header information" why?

P: 79
Do you know why do I get that message when i type a normal setcookie function??

Warning: Cannot modify header information - headers already sent by (output started at c:\programmi\easyphp1.8\www\home.php:5) in c:\programmi\easyphp1.8\www\functions.php on line 92

May 26 '07 #1
Share this Question
Share on Google+
3 Replies

Expert 5K+
P: 5,821
Do you know why do I get that message when i type a normal setcookie function??

For five dollars.

hehe just kidding there.

You're getting that message because your script is outputting something before that statement, specifically on line 5.

Move your setcookie statement to the top of your script (or as close to the top as you can logistically keep it) and eliminate any HTML and/or whitespace before your opening <?php tag.
May 27 '07 #2

P: 79
Eheh! five dollars is too much :D
Thanks dude. I resolved that problem using sessions.
May 27 '07 #3

Expert 5K+
P: 5,058

Just thought I should add this.

Seing as this error is caused because you have already sent the headers to the browser, you can avoid this error by buffering the output and releasing it only when you are ready, using the ob functions.

For example:
Expand|Select|Wrap|Line Numbers
  1. ob_start();
  2. echo "Hello";
  3. header("Content-type: text/html");
  4. ob_end_flush();
Without the ob functions this code would produce the error you encountered.
May 27 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.