Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session_destroy(); not working

Status
Not open for further replies.

DaRNCaT

Technical User
Dec 18, 2002
566
NZ
I'm trying to destroy the shopping cart session once the items have been purchased, but the session seesm to persist, and I don't know how to stop it.

I've used
Code:
session_destroy();

Code:
unset ($_SESSION['PHPSESSID']);
session_destroy();

and
Code:
unset ($_SESSION['cart']);
session_destroy();

None of which work, what am I doing wrong?????

----------------------------------------
Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
you need to do it like this:
Code:
session_start();
session_unset();
session_destroy();

if you used a session name, don't forget to mention it in the session_start statement

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Hi, thanks for that but I've already tried that, I'm wondering if it's not working because I'm swapping from a secure zone to a non secure zone or something?

I have this on a secure page,
Code:
<?php
session_start();
session_unset();
session_destroy();
do some database stuff
?>

this then goes to an unsecure page - index.php which still shows the cart with it's contents, I've tried putting this in the index page

Code:
 session_start();
  if ($_SERVER['HTTP_REFERER'] == "[URL unfurl="true"]https://secure6.webhost-dns.net/~icesplic/php_paypal/success.php"){[/URL]
  session_destroy();
  }

but that doesn't work either, I know it's got to be something simple, but no matter how I fiddle around it seems to persist.

----------------------------------------
Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
hi skiflyer,
can you explain how to use it? as I get errors- I read the manual but I got confused, they recommened so many different things, and I tried them all, I think I'm just mixing them too much or not putting in things which should be there.
thanks

----------------------------------------
Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
Code:
<?php

session_start();

echo '<pre>';
print_r($_SESSION);
echo '<hr />';
$_SESSION=array();  //session is now empty
print_r($_SESSION);
echo '</pre>';
?>

 
I've tried this

Code:
<?php
  // declare the session variables we want access to inside the function 
  session_start();
  if ($_SERVER['HTTP_REFERER'] == "[URL unfurl="true"]https://secure6.webhost-dns.net/~icesplic/php_paypal/success.php"){[/URL]
  $_SESSION=array();
  }
  if(!$_SESSION['items']) $_SESSION['items'] = '0';
  if(!$_SESSION['total_price']) $_SESSION['total_price'] = '0.00';
?>

And it's still not working, I checked the page info, and it says there is no referring URL, is this something to do with it comming from a secure page?
How on earth do I get rid of the sodding session???

----------------------------------------
Sometimes, when my code just won't behave, I take it outside and make it listen to britney spears music, and when it comes back it's really well behaved. I wonder if it's suffering from post tramatic stress syndrome now..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top