setcookie() returns FALSE [message #179698] |
Fri, 23 November 2012 06:26 |
cerr
Messages: 33 Registered: September 2010
Karma: 0
|
Member |
|
|
Hi,
I have the following code:
if(setcookie("FSBO", "TEST", time()+3600)) {
echo "TRUE<br>";
} else {
echo "FALSE<br>";
}
print_r($_COOKIE);
and the ouput on my box is false. How do I know why I can't set a cookie?
Thank you!
|
|
|
Re: setcookie() returns FALSE [message #179699 is a reply to message #179698] |
Fri, 23 November 2012 08:53 |
Olaf S.
Messages: 10 Registered: December 2011
Karma: 0
|
Junior Member |
|
|
Am 23.11.2012 07:26, schrieb cerr:
> Hi,
>
> I have the following code:
> if(setcookie("FSBO", "TEST", time()+3600)) {
> echo "TRUE<br>";
> } else {
> echo "FALSE<br>";
> }
> print_r($_COOKIE);
> and the ouput on my box is false. How do I know why I can't set a cookie?
> Thank you!
>
You many *NOT* output *ANY* Code, before you use setcookie.
NOT any whitespace, not <head> or <html>...or..or
|
|
|
Re: setcookie() returns FALSE [message #179700 is a reply to message #179698] |
Fri, 23 November 2012 09:52 |
M. Strobel
Messages: 386 Registered: December 2011
Karma: 0
|
Senior Member |
|
|
Am 23.11.2012 07:26, schrieb cerr:
> Hi,
>
> I have the following code:
> if(setcookie("FSBO", "TEST", time()+3600)) {
> echo "TRUE<br>";
> } else {
> echo "FALSE<br>";
> }
> print_r($_COOKIE);
> and the ouput on my box is false. How do I know why I can't set a cookie?
The problem is that cookies are set in the HTTP header, which are sent as soon as
there is output. If you had turned all messages on you would see an error message
telling you '...headers sent...'
see http://www.php.net/manual/en/function.headers-sent.php and the links there.
/Str.
|
|
|