Page 1 of 1

Deleted Cookie still calls old value

Posted: Fri Jan 16, 2004 10:40 am
by LegionPete
This issue is this. Have a login page that is suppose to check for a cookie. If the cookie is not there, then it kicks them back to the login page. If it is there, then it checks the value and lets them in. What is actually happening is if they have the direct link to the home page, its suppose to check the for the cookie. It doesn't. Now, if they login in properly, it sets a cookie. If they then clear their cache, remove the cookie, close the browser, Open a new browser, copy and paste the url for the home page, it will return the previous cookie value even though that cookie has been deleted. If refresh is clicked on the page, it will kick them to the login page. This does the same thing if you simply update the cookie with new values and try to call those new values. It will post the old values until you click refresh. I'm lost as to how to get it to properly read the cookie the next time that page is called.

Posted: Fri Jan 16, 2004 10:52 am
by DuFF
Have you checked out the Common Pitfalls on the setcookie page?
Common Pitfalls:

*Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);.

*Cookies must be deleted with the same parameters as they were set with. If the value argument is an empty string (""), and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client.

*Cookies names can be set as array names and will be available to your PHP scripts as arrays but separate cookies are stored on the users system. Consider explode() or serialize() to set one cookie with multiple names and values.