Page 1 of 1

Clearing Stored Cookies

Posted: Mon Feb 23, 2004 7:54 am
by sree78
Hi,

I am having problem clearing the stored cookie when the user log outs. I designed a quiz module which uses cookie. In my sign out page I have this code:-

<?
setcookie ("reg_id", "");
header ("Location:/jen/index.php");
?>

This script works well in explorer but in other browsers, it tens to still keep the user detail so when a user gets in the quiz modules on Guest mode, it is not recongnizing the user as a guest instead using the previous registered user's details. This only gets overwritten if the new user login with his/her uname and psw. But the problem is, we also have a guest mode where a user does not need to necessarily register to take the quizez.

Any idea will be highly appreciated.

Thanks a million :(

Posted: Mon Feb 23, 2004 9:21 am
by Derfel Cadarn
Important tip 8) : never design with just IE in mind. If there's one buggy browser araound, it's IE.

But to the coding: have you checked php.net? It says this about deleting cookies: set the expiration date/time in the past.

Code: Select all

When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser.
Example setcookie() delete example:

Code: Select all

<?php
// set the expiration date to one hour ago
setcookie ("TestCookie", "", time() - 3600);
or:
setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".example.com", 1);
?>
EDIT: Oops, I think I might have just missed your point quite a bit. I'll rethink.... :oops: