Cookie and Session
I have some code to set a cookie, it seems to be working fine, although I can't delete the cookie. Even after the next page runs the code to expire the cookie. Not sure what I'm doing wrong. Any help would be appreciated.
Heres the code to set the cookie:
if(isset($_COOKIE["CartID"]))
{
return $_COOKIE["CartID"];
}
else
{
// There is no cookie set. We will set the cookie
// and return the value of the users session ID
session_start();
setcookie("CartID", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
Here is one of the many ways that I have tried to expire the cookie:
//remove the cookie from the users machine
setcookie("CartID", "session_id()", mktime(12,0,0,1, 1, 1990));
session_start();
$_SESSION = array();
session_destroy();
I have also tried this to destroy the information in the session:
<?php //remove the cookie from the users machine
setcookie("CartID");
session_unregister('PHPSESSID');
unset($_SESSION['PHPSESSID']);
?>
and many other attempts. I have read as much as I can find from google and I have tried pretty much everything that I have read.
I need the session and the cookie information to clear. I have been trying for over 2 days now with about 8-10 hours a day. I'm a little lost and getting frustrated. the set cookie code is on a different page. When a user finishes and clicks to "submit" they are rediredted to a page that only contains the code to remove the cookie and clear the session, they are then redirected once again to the home page. I would like the home page to load as if it were their first visit.
Thanks
|