RE: [PHP] sessions?
| From: | John W. Holmes | Date: | Thu, 17 Apr 2003 01:05:13 +0000 |
| Subject: | RE: [PHP] sessions? | ||
| References: | 1 | Groups: | php.general php.windows |
| Request: | Send a blank email to php-general+get-144218@lists.php.net to get a copy of this message | ||
> Just trying to understand sessions. For example, I have a user login
page
> and a logout page. If 10 people are logged in and three of them log
out -
> how does session_destroy() know which sessions to kill. I understand
there
> are session id's - but not sure how they are assigned to each user and
how
> they are controlled. Now what if I wanted to use another session for a
> chatroom lets say, same question as above - how are these controlled.
I'm
> just trying to further understand how exactly sessions work so that
when I
> am trying to use them I can do so more efficiently.
Sessions are controlled by a 32 character session id that is designed to
be unique for each session that's started. When session_start() is
encounted, it looks for a session id in the URL or in a cookie. If it
does not find one, it creates an ID for the request and puts it in
cookie (by default) or in the URL later. If a session ID already exists
when session_start() is called, PHP (by default) opens a file on the
server related to that unique session id and loads the data from it. At
the end of the PHP file, the new/changed session data is saved back to
the file.
If someone logs out and you use session_destroy(), then the file related
to their session ID is destroyed along with the cookie (I think). Now,
if they come back, they'll get a new session ID and a new empty file.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/