Cookie help.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Xom
Forum Newbie
Posts: 3
Joined: Sun Apr 16, 2006 12:29 am

Cookie help.

Post by Xom »

I am try set a cookie with setcookie and it works fine but it always return true even if I disable cookies in my browser. So do you know what is happening any to fix this is there a other to check if the cookie got set or am I doing this totally wrong?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

showing us the code helps :wink:
Xom
Forum Newbie
Posts: 3
Joined: Sun Apr 16, 2006 12:29 am

Post by Xom »

<?php
$passed = setcookie("name","value",time()+604800);
echo($passed);
?>

$passed always equals 1 even if the cookie was not set.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Reading the documentation would have told you why it returns 1
If output exists prior to calling this function, setcookie() will fail and return FALSE. If setcookie() successfully runs, it will return TRUE. This does not indicate whether the user accepted the cookie.
Xom
Forum Newbie
Posts: 3
Joined: Sun Apr 16, 2006 12:29 am

Post by Xom »

Oh, I feel stupid. So how can I figure if the user accepted the cookie or not?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The cookie data is present on the next page request.
Post Reply