| | |
PHP Session Variables
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2006
Posts: 11
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Aug 2006
Posts: 138
Reputation:
Solved Threads: 2
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.
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.
•
•
Join Date: Mar 2006
Posts: 31
Reputation:
Solved Threads: 3
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.
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
When all that is becomes one. That is the anomoly. That is... Death's Gate Studios (c) 2005
•
•
Join Date: Jan 2006
Posts: 11
Reputation:
Solved Threads: 0
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......
•
•
Join Date: Aug 2006
Posts: 138
Reputation:
Solved Threads: 2
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.
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.
•
•
Join Date: Jan 2006
Posts: 11
Reputation:
Solved Threads: 0
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
[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.
![]() |
Similar Threads
- Session Variables a threat? (VB.NET)
- question about connecting odbc to sql through php script (PHP)
- php help needed for login (PHP)
Other Threads in the PHP Forum
- Previous Thread: how to create subfolders
- Next Thread: PHP work for a television show
| Thread Tools | Search this Thread |
advanced alerts apache api archive array autosuggest beginner binary broken cakephp checkbox class clients cms code cron curl database date datepart display dynamic echo email emptydisplayvalue eregi error execute explodefunction file files folder form forms function functions google hack head href htaccess html if...loop image include insert ip javasciptvalidation javascript joomla keywords library limit link login mail matching menu mlm multiple mysql number object oop password paypal pdf php phpincludeissue query radio random recursive remote script search searchbox server sessions shot smarty source space speed sql syntax system table tutorial update upload url validator variable vbulletin video web website youtube





