944,103 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 9519
  • PHP RSS
Feb 7th, 2007
0

PHP Session Variables

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaikar is offline Offline
11 posts
since Jan 2006
Feb 7th, 2007
0

Re: PHP Session Variables

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.
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006
Feb 7th, 2007
0

Re: PHP Session Variables

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.
Reputation Points: 10
Solved Threads: 3
Light Poster
DGStudios is offline Offline
31 posts
since Mar 2006
Feb 8th, 2007
0

Re: PHP Session Variables

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......
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaikar is offline Offline
11 posts
since Jan 2006
Feb 8th, 2007
1

Re: PHP Session Variables

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.
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006
Feb 8th, 2007
0

Re: PHP Session Variables

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaikar is offline Offline
11 posts
since Jan 2006
Feb 8th, 2007
0

Re: PHP Session Variables

No, if you check the default setting for session.cookie_lifetime, it's 0.
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006
Feb 11th, 2007
0

Re: PHP Session Variables

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaikar is offline Offline
11 posts
since Jan 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to create subfolders
Next Thread in PHP Forum Timeline: PHP work for a television show





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC