Page 1 of 1

Bizarre Headers Error when setting Cookies

Posted: Tue Aug 19, 2014 4:01 am
by simonmlewis
[text]Warning: Cannot modify header information - headers already sent by (output started at /home/j562595/public_html/site/a_sitelogin.php:16) in /home/j56259544/public_html/site/a_sitelogin.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at /home/j562595/public_html/site/a_sitelogin.php:16) in /home/j56259544/public_html/site/a_sitelogin.php on line 18

Warning: Cannot modify header information - headers already sent by (output started at /home/j562595/public_html/sites/a_sitelogin.php:16) in /home/j56259544/public_html/site/a_sitelogin.php on line 19

Warning: Cannot modify header information - headers already sent by (output started at /home/j562595/public_html/site/a_sitelogin.php:16) in /home/j56259544/public_html/site/a_sitelogin.php on line 20

Warning: Cannot modify header information - headers already sent by (output started at /home/j562595/public_html/site/a_sitelogin.php:16) in /home/j56259544/public_html/site/a_sitelogin.php on line 21[/text]

We are now hosting about 5 sites on a new service. All are ok. We can login to them all fine - except this one.
The cost is the same, except this uses PDO.

For some reason, it won't let us set Cookies. If I echo the output of the database query, it shows the data, but just won't set the cookies.
I don't know what ..... .php:16 means either.

Why would all the sites work, but this one? The code is the same. Especially the SetCookie code.

Re: Bizarre Headers Error when setting Cookies

Posted: Tue Aug 19, 2014 6:57 am
by Celauran
It's complaining about something on line 16 of a_sitelogin.php. What's going on there?

Re: Bizarre Headers Error when setting Cookies

Posted: Tue Aug 19, 2014 7:24 am
by simonmlewis

Code: Select all

while ($row = mysql_fetch_object($result)) 
	{
	echo "<b>$row->email</b><br/><b>$row->type</b>";
setcookie("user", $row->firstname, time()+13600);
setcookie("email", $email, time()+13600);
setcookie("userid", $row->id, time()+13600);
setcookie("type", $row->type, time()+13600);
setcookie("username", $row->username, time()+13600);
Line 14 > line 21 shown above. The same as our other web sites.

It's not storing the cookies.

Re: Bizarre Headers Error when setting Cookies

Posted: Tue Aug 19, 2014 7:31 am
by Celauran
setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace.
setcookie()

Re: Bizarre Headers Error when setting Cookies

Posted: Tue Aug 19, 2014 7:37 am
by simonmlewis
Probably... but then ALL (and I mean ALL) our web sites that use Cookies, run correctly without a hitch, like this.
So why is this one web site doing this.
We now have three domains on this server, and they all have idential scripts.

Re: Bizarre Headers Error when setting Cookies

Posted: Tue Aug 19, 2014 7:58 am
by simonmlewis
Sorted it.
I had echoed something before it, but only to test. Now I have removed it - it works. Yet it wasn't there before and didn't work! lol