Jump to content

Session not destroying


petenaylor

Recommended Posts

Hi all

 

I have a checkout sequence that adds items, prices etc... into an SQL Database with a session id that is started on every page in my header.

 

I have written a success page that uses session_destroy(); but it doesn't unset the $sessionid variable. I have also tried to unset($sessionid) but it keeps the session id?

 

Please help!

 

Many thanks.

 

Pete

Link to comment
Share on other sites

just re-read the OP, are you trying to actually use session_destroy() on the variable that holds your $_SESSION value? if so, that wont work...you will need to do something like

<?php

session_start();
session_destroy($_SESSION['id']);

?>

where your index "id" would be whatever you named your session, also, if you wanted to destroy every session you have created you can use redixx method, however be careful, because it will destroy EVERY session that is initialized

Link to comment
Share on other sites

just re-read the OP, are you trying to actually use session_destroy() on the variable that holds your $_SESSION value? if so, that wont work...you will need to do something like

<?php

session_start();
session_destroy($_SESSION['id']);

?>

where your index "id" would be whatever you named your session, also, if you wanted to destroy every session you have created you can use redixx method, however be careful, because it will destroy EVERY session that is initialized

 

What do you mean by all sessions? It will only destroy that user's session.

Link to comment
Share on other sites

that's what i mean, if the he has sessions stored for lets say his login credentials the user will be logged out if his login is based off of sessions

 

Gotcha.

 

OP, in case you don't want that to happen you can unset individual session keys like this:

unset($_SESSION['key']);

Link to comment
Share on other sites

Hi all

 

Thanks for the replies, I have added the following into the code but it still doesn't destroy my session?

 

session_destroy($sessionid);

 

On each of my pages I have session_start(); as it's included in my config file which is included in my header on each page.

 

I have preview of the shopping cart on each page too which looks like this:

 

<?php 
  $getheaderbasket = mysql_query("SELECT * FROM `store_basket` WHERE sessionid = '".$sessionid."'") or die (mysql_error());
  $numproductsheaderbasket = mysql_num_rows($getheaderbasket);
  
  
  while ($showheaderbasket = mysql_fetch_array($getheaderbasket)) { 
  
  // Work out totals:
  
  $header_item_total = $showheaderbasket['qty'] * $showheaderbasket['price'];
  $header_item_total = number_format($header_item_total, 2);
  $header_subtotal += $header_item_total;
  
  }
  ?>

 

Am I right in thinking that if the session is destroyed, the above shoudn't find any products as the $sessionid is destroyed?

 

Many thanks for you help.

 

Pete

Link to comment
Share on other sites

I see. Basically, when a user checks out I want to keep the basket details in the SQL as they are.

 

The basket has the session id, product, price and shipping cost. When they complete checkout, I want the session id to be reset so that if they place another order, it adds a new sessionid into the basket.

 

Thanks for your help.

 

 

Link to comment
Share on other sites

You cannot use session_destroy() on a variable. You must enter the session itself into the function.

session_destroy($_SESSION['id'])

To unset the variable holding the value of your session you can use the method that the previous poster provided

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.