My session refuses to be destroyed!
I'm using sessions to help control a checkout process and I have a header file that I include on just about all the pages. The very first line of it is session_start();
Everything works fine, all through the checkout. This snippet, on the page that actually processes the payment, redirects the user upon successful transaction to a page that is supposed to clear the session data:
if($result == "Success") {
$fromaddress = 'myemail@myemail.com';
$eol="\r\n";
$mime_boundary=md5(time());
$headers .= 'From: Moi <'.$fromaddress.'>'.$eol;
$headers .= 'Reply-To: Moi <'.$fromaddress.'>'.$eol;
$headers .= 'Return-Path: Moi <'.$fromaddress.'>'.$eol;
$headers .= "Message-ID: <".$now." system@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$emailsubject = 'Order Confirmation';
$msg = 'Thank you for your order.';
if(mail($email_posted, $emailsubject, $msg, $headers)) {
$url = "http://www.mysite.com/store/site2/orderConfirm.php";
if(headers_sent()) {
echo "<script type='text/javascript'>location.href='$url';</script>";
} else {
header("Location: $url");
}
It does redirect, so I know that the transaction has been successful. On the "Thank you" page, I have this:
<?php
session_unset();
session_destroy();
$_SESSION = array();
include '_incs/header.php'; // including my header file again
?>
<font size="3"><b>Thank you for your order!</b></font>
<p>Your receipt has been emailed to you.
<?php
print_r($_SESSION);
?>
The print_r($_SESSION) outputs:
Array ( [cart] => Array ( [1439] => 1 [1430] => 1 [1427] => 1 [1429] => 1 ) )
Why is this? I've unset the sessions, haven't I? Why won't it clear? Interestingly, if I then browse my store, add products to my cart, I'll see all of these items in my cart. I'll go through the payment process, which takes me to a third-party processor, return to my site to complete the transaction, and then magically, the only item in my cart is the one I just added.
I'm going crazy! What's wrong? Happy to post more code, just tell me what's needed.
Thanks