Re: Destroying a Session
| From: | Torsten Roehr | Date: | Wed, 25 Aug 2004 17:53:43 +0000 |
| Subject: | Re: Destroying a Session | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-194699@lists.php.net to get a copy of this message | ||
"Shaun" <shaunthornburgh@hotmail.com> wrote in message
news:20040825162839.62658.qmail@pb1.pair.com...
>
> <john@johnallsopp.co.uk> wrote in message
>
> news:50140.82.195.101.197.1093435673.squirrel@www.johnallsopp.co.uk...
> > >> function clear_orderinfo() {
> > >> global $_SESSION;
> > >> unset($_SESSION["orderinfo"]);
> > >> }
> > >>
> > >> However this function doesnt seem to work and the session remains
> > >> active, is
> > >> there another way to clear a session?
> >
> > I'm not triffically experienced, but I do have notes on the subject.
> > You're wanting to clear the whole session, right?
> >
> > $_SESSION=array();
> > session_destroy();
> >
> > For specific variables, try assigning FALSE to it
> > ($_SESSION['name']=FALSE; or 'unset' works for versions >=4.2.2.
Otherwise
> > use session_unregister. For me under 4.1.2 I had to set to null.
> >
> > HTH
> > J
> >
> >
>
> Hi,
>
> Thank you for your replies. I am using version 4.3.3 yet unset() doesn't
> seem to work. To test this I have placed this line of code in my
footer.php
> file that appears at the bottom of every page:
>
> echo 'load_orderinfo() = '.load_orderinfo();
>
> Here is the load_orderinfo() function:
>
> function load_orderinfo() {
> global $_SESSION;
> if (empty($_SESSION["orderinfo"])) {
> return false;
> } else {
> return $_SESSION["orderinfo"];
> }
> }
>
> Before the $_SESSION["orderinfo"] is created the output in the footer
reads:
>
> load_orderinfo() =
>
> When it has been created it reads:
>
> load_orderinfo() = Object;
>
> On the complete_order.php page where I call the clear_orderinfo() function
> it goes back to:
>
> load_orderinfo() =
>
> but it on any subsequent page the output returns to:
>
> load_orderinfo() = Object;
>
> But after calling the clear_orderinfo() function surely the
> $_SESSION["orderinfo"] should have been destroyed. I hope this makes
sense!
>
> Thanks for your help
Hi,
remove the global $_SESSION; lines in your functions - they are uneccessary.
Have you tried resetting $_SESSION instead of unset()?:
$_SESSION = array();
Regards, Torsten Roehr