FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » setcookie() returns FALSE
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
setcookie() returns FALSE [message #179698] Fri, 23 November 2012 06:26 Go to next message
cerr is currently offline  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 Go to previous messageGo to next message
Olaf S. is currently offline  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 Go to previous message
M. Strobel is currently offline  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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: PHP 5.5 and Windows XP
Next Topic: Tokenize an HTML page.
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 13:53:53 GMT 2024

Total time taken to generate the page: 0.02398 seconds