Clearing Stored Cookies

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
sree78
Forum Commoner
Posts: 39
Joined: Tue May 20, 2003 11:38 am

Clearing Stored Cookies

Post 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 :(
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post 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:
Post Reply