Forum Moderators: coopster

Message Too Old, No Replies

Error: Headers already sent?

         

Gero_Master

1:29 pm on Jun 4, 2006 (gmt 0)

10+ Year Member



Hello!

I had this problem when I was making a language changing script for my site.

I have 1 PHP document and another included to it in the beginning of the page.

This is all referring to headers in the included page:
session_start();
header("Cache-control: private");

On the main page I tried to set cookie:
setcookie("use_lang", $_GET['newlang']);

It gives me this error:

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\WebTicks\profile.php:15) in C:\Program Files\xampp\htdocs\WebTicks\profile.php on line 102

Mohamed

2:39 pm on Jun 4, 2006 (gmt 0)

10+ Year Member



I am not that good in php but I think you should set cookie before calling the header. like this way.

session_start();
setcookie("use_lang", $_GET['newlang']);
header("Cache-control: private");

siMKin

3:15 pm on Jun 4, 2006 (gmt 0)

10+ Year Member



because the cookie has to be sent with the header, you have to set the cookie before you generate any output.

dreamcatcher

4:29 pm on Jun 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can also use Output Buffering to get around this issue.

[uk.php.net...]

dc

Gero_Master

6:30 am on Jun 5, 2006 (gmt 0)

10+ Year Member



Thank you all, I managed to fix the bug