Page 1 of 1
php sessions
Posted: Mon Jul 20, 2009 7:45 am
by netcode
Hello there,
I am have two questions about php sessions.
1. Is it required to start a session every new page if you want to continue the session?
2. When does session data get dropped from the server?
Thanks.
I am sure the answer will lead into more discussion
B.
Re: php sessions
Posted: Mon Jul 20, 2009 8:05 am
by jazz090
1. yes but that is if you need session data (you need to access $_SESSION), if you are not going to use session data dont call session_start()
2. never (session data is always on your server, the session key is trapped in a cookie for the user and that is whats deleted from the users pc when the session ends)
Re: php sessions
Posted: Mon Jul 20, 2009 8:38 am
by netcode
jazz090 wrote:1. yes but that is if you need session data (you need to access $_SESSION), if you are not going to use session data dont call session_start()
2. never (session data is always on your server, the session key is trapped in a cookie for the user and that is whats deleted from the users pc when the session ends)
1. If I start a session on one page, skip the session on the next page, and start a session again on the 3rd page, will it be in the same session as the first page? I guess that might even be a question about the way a browser handles cookies huh?
2. Is there any way to clear this data? Eventually would session data begin to take up significant space (if there are 1000's of sessions)?
Thanks for your quick reply!
B.
Re: php sessions
Posted: Mon Jul 20, 2009 8:50 am
by jazz090
1. well session data is passed in 2 ways via the URL as a query string or as cookies. most php apps use cookies to store session data,
so if session_start() is skipped in one page, the cookie still gets passed around and still exists in the browser so when session_start() is called it will use the same key it did the last time so it will be the same session. for URL based, it will open the session which the key was passed in the URL so theoretically you can jump from 2 different sessions.
2. session_destroy()
Re: php sessions
Posted: Mon Jul 20, 2009 8:54 am
by netcode
jazz090 wrote:1. well session data is passed in 2 ways via the URL as a query string or as cookies. most php apps use cookies to store session data,
so if session_start() is skipped in one page, the cookie still gets passed around and still exists in the browser so when session_start() is called it will use the same key it did the last time so it will be the same session. for URL based, it will open the session which the key was passed in the URL so theoretically you can jump from 2 different sessions.
I assume cookies are dropped on the users end when the browser window is closed?
Re: php sessions
Posted: Mon Jul 20, 2009 9:00 am
by jazz090
dropped on the users end? what does that mean? if you mean the cookie is deleted then yes given the expire cookie time is set to 0 in php.ini which is 0 by default.
Re: php sessions
Posted: Mon Jul 20, 2009 2:11 pm
by netcode
jazz090 wrote:dropped on the users end? what does that mean? if you mean the cookie is deleted then yes given the expire cookie time is set to 0 in php.ini which is 0 by default.
Sorry I am not one for terminology, I have a bad habit of using slang.
Your assumption is right.
All this information has been very useful, thanks!
B.