Hi there,
So I’m making a shopping cart. Each cart is identified by a user_session_id which is stored in a cookie like so:
if(isset($_COOKIE['SESSION'])) $uid = $_COOKIE['SESSION'];
else $uid = md5(uniqid('biped', true));
setcookie('SESSION', $uid, time()+(60*60*24));
Once the transaction is completed I need to delete the cookie and destroy the session, which I do like so:
$_SESSION = array();
setcookie('SESSION', '', time() - 3600);
session_destroy();
But it doesn’t seem to want to work. When I initialise a new shopping cart it is given the same user_session_id as the previous one. This is bad.
What am I doing wrong? My guess is the line that even though I have set the cookie to a time in the past, the browser has not expired it by the time the new cart is initialised. Do I need to unset the cookie as well? Like so:
$_SESSION = array();
setcookie('SESSION', '', time() - 3600);
unset($_COOKIE['SESSION']);
session_destroy();
Many thanks,
Mike