$_SESSION problem - page reload creates new Session ID

This is a discussion on $_SESSION problem - page reload creates new Session ID within the PHP Language forums, part of the PHP Programming Forums category; Hello, Yes, everything works on individual pages. So I can set session variables and later make references to them or ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 12-11-2004
Mimi
 
Posts: n/a
Default Re: $_SESSION problem - page reload creates new Session ID

Hello,

Yes, everything works on individual pages. So I can set session variables
and later make references to them or print them out on the screen.
What is not working is accessing session vars that have been already
set on a page just viewed because there is a new session created
when the page is loaded.

What is also strange is that every time I try to refresh any page on my app,
a new session is created and don't understand why !? And that is the reason
I
can not pinpoint the problem.

Thanks anyway for trying to help.



"Pedro Graca" <hexkid@dodgeit.com> wrote in message
news:slrncrkb3g.ln2.hexkid@ID-203069.user.uni-berlin.de...
> Mimi wrote:
>> There is one thing I forgot to mention:
>>
>> On my application I am using FRAMES, and I noticed one strange thing:

>
> Frames shouldn't be a problem (as far as session data is concerned --
> frames are bad!).
>
> A simple script with sessions works for you with your current
> configuration?
>
>
> ========
> <?php
> session_start();
> if (!isset($_SESSION['hits'])) $_SESSION['hits'] = 0;
> ++$_SESSION['hits'];
>
> echo '<p>Session hits: ', $_SESSION['hits'], '</p>';
> echo '<p>Refresh the page or click <a href="', $_SERVER['PHP_SELF'],
> '">here</a>.';
> ?>
> --------
>
>
> At every refresh this page /should/ keep increasing the displayed number
> of hits. Does it?
>
> --
> Mail to my "From:" address is readable by all at http://www.dodgeit.com/
> == ** ## !! ------------------------------------------------ !! ## ** ==
> TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
> may bypass my spam filter. If it does, I may reply from another address!




Reply With Quote
  #12 (permalink)  
Old 12-11-2004
Mimi
 
Posts: n/a
Default Re: $_SESSION problem - page reload creates new Session ID

Now this is ridiculous:
After all this fuss I found out what the problem was:

I have ZoneAlarm installed on this computer but under "Cookie Control"
I let session and persistent cookies get through. I only disabled "Third
Party Cookies"

Immediately when I enabled "Third Party Cookies" the session was working as
intended.

I am not sure why ZoneAlarm would consider the local session files as "third
party" ?!

Anyways, Thank You all


"Mimi" <mimi@coco.com> wrote in message
news:2Irud.69$z66.4@fe61.usenetserver.com...
> Hello,
>
> Yes, everything works on individual pages. So I can set session variables
> and later make references to them or print them out on the screen.
> What is not working is accessing session vars that have been already
> set on a page just viewed because there is a new session created
> when the page is loaded.
>
> What is also strange is that every time I try to refresh any page on my
> app,
> a new session is created and don't understand why !? And that is the
> reason I
> can not pinpoint the problem.
>
> Thanks anyway for trying to help.
>
>
>
> "Pedro Graca" <hexkid@dodgeit.com> wrote in message
> news:slrncrkb3g.ln2.hexkid@ID-203069.user.uni-berlin.de...
>> Mimi wrote:
>>> There is one thing I forgot to mention:
>>>
>>> On my application I am using FRAMES, and I noticed one strange thing:

>>
>> Frames shouldn't be a problem (as far as session data is concerned --
>> frames are bad!).
>>
>> A simple script with sessions works for you with your current
>> configuration?
>>
>>
>> ========
>> <?php
>> session_start();
>> if (!isset($_SESSION['hits'])) $_SESSION['hits'] = 0;
>> ++$_SESSION['hits'];
>>
>> echo '<p>Session hits: ', $_SESSION['hits'], '</p>';
>> echo '<p>Refresh the page or click <a href="', $_SERVER['PHP_SELF'],
>> '">here</a>.';
>> ?>
>> --------
>>
>>
>> At every refresh this page /should/ keep increasing the displayed number
>> of hits. Does it?
>>
>> --
>> Mail to my "From:" address is readable by all at http://www.dodgeit.com/
>> == ** ## !! ------------------------------------------------ !! ## ** ==
>> TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
>> may bypass my spam filter. If it does, I may reply from another address!

>
>
>




Reply With Quote
  #13 (permalink)  
Old 12-11-2004
Pedro Graca
 
Posts: n/a
Default Re: $_SESSION problem - page reload creates new Session ID

Mimi wrote:
> Yes, everything works on individual pages.


Ok. So it is not a problem with the server.

> So I can set session variables
> and later make references to them or print them out on the screen.


Just re-checking:
When you say later, do you mean later in the same script (like setting
$_SESSION['something'] = 42 in line 17 and echoing that in line 163)
or later in another request for possibly another URL?

> What is not working is accessing session vars that have been already
> set on a page just viewed because there is a new session created
> when the page is loaded.
>
> What is also strange is that every time I try to refresh any page on my app,
> a new session is created and don't understand why !? And that is the reason
> I can not pinpoint the problem.


As fas as the server is concerned all requests are independant.

Between two requests of your browser, there could have been a hundred
requests from other browsers. PHP needs a way to identify that this
101st request is the one to associate with the first and recreate the
session variables. It does that because on the first session_start() it
sent the browser a cookie with the session id and the browser sends the
cookie back to the server. PHP then checks in session.save_path for a
file corresponding to that cookie and recreates the session variables.


Something like this happens:

CLIENT => Hey! Gimme "index.php"
SERVER <= I'm going to keep a few values for you saved on my disk.
In order for me to fetch them later I ask you to send
me back the "PHPSESSID=0123456789abcdef" cookie.

ANOTHER CLIENT => same thing here
SERVER (TO ANOTHER CLIENT) <= almost the same thing (different
session id)

...
100 more requests
...

CLIENT (you again) => Hey! Gimme "list.php"
You stored data for me on your disk. The key
to that data is "PHPSESSID=0123456789abcdef"
SERVER <= Ok, keep sending me the key to the data and all is well


if the browser didn't send the cookie, PHP thinks it is a request
that is independant of the first and will create a brand new session
id for it (with the corresponding file in the session.save_path
directory).



Another way for the browser to tell the server what session to use,
instead of using cookies, is to pass the session id in the URL or in a
(hidden) form field




So, I guess your browser is not sending the session id back to the
server for that specific page you're having problems with.

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Reply With Quote
  #14 (permalink)  
Old 12-13-2004
Erwin Moller
 
Posts: n/a
Default Re: $_SESSION problem - page reload creates new Session ID

Mimi wrote:


Hi Mimi,

Glad you solved it.


> Now this is ridiculous:
> After all this fuss I found out what the problem was:
>
> I have ZoneAlarm installed on this computer but under "Cookie Control"
> I let session and persistent cookies get through. I only disabled "Third
> Party Cookies"


Woot?
That sounds strange...
I use ZoneAlarm too on my M$-box, but NEVER had trouble like this.
Maybe you hitted some obscure bug in Zonealarm?
Please contact them.

>
> Immediately when I enabled "Third Party Cookies" the session was working
> as intended.
>
> I am not sure why ZoneAlarm would consider the local session files as
> "third party" ?!
>
> Anyways, Thank You all
>


You are welcome.

Regards,
Erwin Moller
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:38 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0