[SOLVED] Cookie question

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
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

[SOLVED] Cookie question

Post by evilmonkey »

Hello everyone.

I have a question regarding a cookie. When a cookie is set, using setcookie() in PHP, and an expiry date is set (to one year from now), the data in the cookie is easily read by PHP and passed to whereever it needs to be passed. For example:

Code: Select all

<?php setcookie("cookiename", $sessid, time()+60*60*24*30*12, "/"); ?>
Now, my question is, what happens when I do something like this?

Code: Select all

<?php setcookie("cookiename", "",  time()-3600); ?>
After this command is run, if I do a check on the cookie (such as if (isset($_COOKIE['cookiename']))), should that condition still pass? In other words, is the cookie still set?

Thanks!
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

1st ... try it your self it wont hurt to see if it works or not

2nd... i believe the cookie will be unset so the if (isset($_COOKIE['cookiename'])) will return false
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

I tried it out,I got that the cookie is still set, and was wondering if this is normal behaviour. I'll go back to my code, see if I missed something. Thanks!
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

OH DARN!!!

I just remebered something. The page needs to be refreshed in order for the cookie information to change right? That was my downfall. The code is fine. :D

Thanks!
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

lol a refresh is a needy =]
Post Reply