PHP Session Variables

Reply

Join Date: Jan 2006
Posts: 11
Reputation: jaikar is an unknown quantity at this point 
Solved Threads: 0
jaikar jaikar is offline Offline
Newbie Poster

PHP Session Variables

 
0
  #1
Feb 7th, 2007
Hi !,

I have some questions on session variables,

when a user logs in to a site, then opens a link in a different browser will the same session continue for the second browser ?..... i hope so... and if the session continues with the second browser and the user closes the second browser will the session come to an end but still he kept his first browser opened !... a bit confusing for me..

hope i will get a answer .. also not sure if my question is correct !...

Thanks !!

~J
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: PHP Session Variables

 
0
  #2
Feb 7th, 2007
No, that's not the case. The session id is saved in a cookie, which is browser specific. Thus opening a new browser starts another session.

The workaround would be saving the session id in a database along with an ip. That way you can pick the session by an ip, not a cookie, thus making the same session available in different browsers on the same computer.
Last edited by php_daemon; Feb 7th, 2007 at 3:02 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 31
Reputation: DGStudios is an unknown quantity at this point 
Solved Threads: 3
DGStudios DGStudios is offline Offline
Light Poster

Re: PHP Session Variables

 
0
  #3
Feb 7th, 2007
That is both correct and incorrect. The second page will NOT identify the session when it opens. However a session will NOT end until you tell it to end or it times out. Even if it is stored in a cookie.

The purpose of using sessions is so that your user can close the browser and come back in a new window. So it will still be preserved, this much I have delt with on the forum I built. However, the second page MUST include the Session_start() function or it will not even pay any attention to the fact that you have an active session.
http://img.photobucket.com/albums/v6.../dgstudios.jpg
When all that is becomes one. That is the anomoly. That is... Death's Gate Studios (c) 2005
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 11
Reputation: jaikar is an unknown quantity at this point 
Solved Threads: 0
jaikar jaikar is offline Offline
Newbie Poster

Re: PHP Session Variables

 
0
  #4
Feb 8th, 2007
yes !.. session id is stored in a cookie... but the above 2 replies seems to be completly contradict. There are cases where a session will end once the browser is closed like gmail. what will happen in that case when a link is opened in a different window?. and if i go with what php_deamon said, then will a new cookie get created if opened in a seperate window for those cases where session is not ended by closing the browser like how DG said, like... the purpose is to retain a session when a browser is closed and opend again... but if a link is opend in a different window will it create a new cookie......
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: PHP Session Variables

 
1
  #5
Feb 8th, 2007
There are two session types: persistent and simple sessions.

The persistent sessions are established by setting a session cookie lifespan for a specific period (for example a month). In this case, they work as DGStudios described.

However, the sessions are not persistent by default. The cookie is kept only until the browser is closed. If you close the browser, the session is no longer alive the next time you open it. As far as the new windows, it depends whether you open it by following the link or run a different instance of a browser. When you follow a link to a new window, that window is a child of the main window and shares the same cookie information. But if you run a different instance of a browser, the sessions do not persist.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 11
Reputation: jaikar is an unknown quantity at this point 
Solved Threads: 0
jaikar jaikar is offline Offline
Newbie Poster

Re: PHP Session Variables

 
0
  #6
Feb 8th, 2007
FABULOUS !!..
thats really very nice usefull piece of information by php_daemon ! Thanks !

so if i am correct... the simple sessions are created by setting the cookie date to the past on the header of a php page... right ? .... i am not exactly sure though
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: PHP Session Variables

 
0
  #7
Feb 8th, 2007
No, if you check the default setting for session.cookie_lifetime, it's 0.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 11
Reputation: jaikar is an unknown quantity at this point 
Solved Threads: 0
jaikar jaikar is offline Offline
Newbie Poster

Re: PHP Session Variables

 
0
  #8
Feb 11th, 2007
yes... thats in the server !!.. but if the session lifetime in the server is set to infinite then using the code below you can make the session lifetime to 0.

[PHP]header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
[/PHP]

~J
Last edited by jaikar; Feb 11th, 2007 at 7:12 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC