-
Delete cookie not working (PHP)
I am using PHP, running on Windows Server 2003. Tested in Firefox/IE latest versions.
I want to delete the cookie when the user has logged out, but having no joy whatsoever! I've researched this to death, and found the code to be valid, but it doesn't work - can anyone shed some light on this pls?
Part 1 of the code creates the cookie when logging in:
<?php
if (isset($HTTP_POST_VARS['username'])) {
setcookie("myCookie", $HTTP_POST_VARS['username'], time()+3600);
}
?>
Part 2 of the code is the logout code:
<?php
//initialize the session
session_start();
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
session_unregister('MM_Username');
session_unregister('MM_UserGroup');
// delete the cookie when logging out
setcookie("myCookie", "", time()-3600);
$logoutGoTo = "../index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
Part 3 of the code is the link itself:
<?php
echo '<a href="'. $logoutAction. '" target="_self">Logout</a>';
}
?>
-
Anyone??
-
Well I'm not a php coder but in other languages, the cookie expiration date being set to some time in the past will delete the cookie
-
Hi
Sure, which is what I have done, like this:
setcookie("myCookie", "", time()-3600);
Maybe the code isn't being ran at all (it is currently part of the logout code) - so what I will do is redirect the user to a dedicated logout.php page, where the cookie is deleted.
I will post an update soon...
-
Success!
Ok, aside from wanting to swear at this nonsense, I removed the cookie deletion code from the logout code, put the delete cookie code on a seperate page and viola! it works.
-
Similar Threads
-
By Wildcatbob in forum Web
Replies: 3
Last Post: 06-23-2006, 05:44 AM
-
Replies: 0
Last Post: 05-15-2006, 09:45 AM
-
By AaronD in forum Careers
Replies: 0
Last Post: 02-03-2006, 07:49 PM
-
By vbcoder in forum VB Classic
Replies: 9
Last Post: 04-28-2005, 12:36 PM
-
By AAnthony in forum .NET
Replies: 0
Last Post: 06-11-2001, 05:32 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks