petenaylor Posted June 16, 2011 Share Posted June 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/ Share on other sites More sharing options...
fugix Posted June 16, 2011 Share Posted June 16, 2011 make sure you have session_start() at the top of the [age you are using to destroy your session..if you do, please show us your code Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230824 Share on other sites More sharing options...
redixx Posted June 16, 2011 Share Posted June 16, 2011 Try: unset($_SESSION); session_destroy(); Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230827 Share on other sites More sharing options...
fugix Posted June 16, 2011 Share Posted June 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230831 Share on other sites More sharing options...
redixx Posted June 16, 2011 Share Posted June 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230833 Share on other sites More sharing options...
fugix Posted June 16, 2011 Share Posted June 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230834 Share on other sites More sharing options...
redixx Posted June 17, 2011 Share Posted June 17, 2011 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']); Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230861 Share on other sites More sharing options...
petenaylor Posted June 17, 2011 Author Share Posted June 17, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230923 Share on other sites More sharing options...
revraz Posted June 17, 2011 Share Posted June 17, 2011 $sessionid isn't destroyed, $_SESSION is destroyed. Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230924 Share on other sites More sharing options...
petenaylor Posted June 17, 2011 Author Share Posted June 17, 2011 OK, how do I destroy $sessionid so that it creates a new one for use with my basket? Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230925 Share on other sites More sharing options...
revraz Posted June 17, 2011 Share Posted June 17, 2011 $sessionid = ""; Why does it have to be destroyed, just overwrite it? I think you are confusing variables with session variables. Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230929 Share on other sites More sharing options...
petenaylor Posted June 17, 2011 Author Share Posted June 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1230930 Share on other sites More sharing options...
fugix Posted June 17, 2011 Share Posted June 17, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1231215 Share on other sites More sharing options...
xyph Posted June 17, 2011 Share Posted June 17, 2011 Why not simply move the row out of `store_basket` and into a `checked_out` table... then you can continue to use the same session with a fresh basket. Quote Link to comment https://forums.phpfreaks.com/topic/239597-session-not-destroying/#findComment-1231219 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.