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

Home » Imported messages » comp.lang.php » setcookie() returns FALSE
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
setcookie() returns FALSE [message #179698] Fri, 23 November 2012 01:26 Go to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
add to buddy list
ignore all messages by this user
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 03:53 Go to previous messageGo to next message
Olaf S. is currently offline  Olaf S.
Messages: 10
Registered: December 2011
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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 04:52 Go to previous message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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.
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
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: Sun Dec 10 23:12:40 EST 2017

Total time taken to generate the page: 0.00686 seconds