Re: session ok? [SOLVED]
| From: | Micah Gersten | Date: | Mon, 21 Jul 2008 15:16:48 +0000 |
| Subject: | Re: session ok? [SOLVED] | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-277145@lists.php.net to get a copy of this message | ||
When you use a header redirect, you start with a new page. Everything
you did until then is gone. When you call session_start on the new
page, it resumes the same session, not creates a new one.
Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com
tedd wrote:
> Hi gang:
>
> I found the problem I was having with sessions and want to share it
> with you -- it surprised me.
>
> To refresh -- I was having a problem with destroying a session. I went
> through all the steps shown in the manual and dozens of recommended
> ways of doing it I found on the net.
>
> However, I found that while I was actually destroying the session I
> wanted, another session was being created in a very unexpected way.
>
> Now, the manual says:
>
> "session_start() creates a session or resumes the current one based on
> the current session id that's being passed via a request, such as GET,
> POST, or a cookie."
>
> From that one assumes that if you place a session_start at the
> beginning of each page, then the first time it's encountered, a
> session will be created and with every encounter thereafter the
> established session will be used.
>
> That's the way it works PROVIDED that you do not use the following in
> your code:
>
> header('Location:
> http://www.yourdomain.com/whatever/index.php');
>
> If you use that statement, then a new session will be created AND you
> will find that you'll have two sessions working concurrently. That
> creates several problems -- one of them being while you may destroy
> the first session, the second will be still remain.
>
> Now, how many people knew this?
>
> Am I the only one who didn't?
>
> Cheers,
>
> tedd