Forum Moderators: coopster

Message Too Old, No Replies

How do different sessions work? Multiple Sessions

         

Frank_Rizzo

5:56 pm on Jul 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use a messageboard which uses sessions.

I have a login script which uses sessions.

I have a charting app which uses sessions.

How does PHP handle this? Does it create three different sessions or is everything handled by the one session file? In other words, is it working like magic and I don't need to worry about it.

What I'm confused with is that at the start of the login script there is a start_session() and other session related stuff. On logout, the session is destroyed.

Now does this affect the start_session() of the other scripts?

mcibor

9:46 pm on Jul 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Php session [php.net] is done thus:

1. session_start() -> if none session, then one is created (id - random, not repeating alfanumeric string), one file is created in secured place (without http access)

2. all variabled are stored in that file

3. you can store and retrieve the variables by super global $_SESSION

4. session id is passed via session cookie or url www.example.com/index.php?SID=987asdjhg98764kjhga9876...

Therefore to your questions:
- hard to say. There may be one session for all three, or each destroys previous session. (There can be only one session at a time!)
- start_session() should be in every file, unless you use session.auto_start = 1, if you don't have it then the actual session will be destroyed. Don't use in includes.
- session_destroy() will destroy that session - you loose any information stored there.

Use session just to pass relevant data concerning that particular user.
hope this helps
Michal CIbor

Frank_Rizzo

10:37 pm on Jul 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, still confused about this.

If first the login script initiates session file.
Second, the user access the message board
Third, the user generates a chart
Fourth, the user logouts of the message board (which has a session_destroy()

Then what happens to the login and if he wants to produce another chart?

mcibor

9:12 am on Jul 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Let's assume that only logout destroys the session. Then:

-Once you are logged in you have 1 session.
-all the scripts use that session (message board and chart)
-user can creates as many charts as he wishes
-after logout user can't do anything but log in.

If the scripts are written properly you do not have to worry about anything:)
Login is shown only when the session is destroyed, so after log out, not after making chart

Hope this will help
Michal Cibor

PS. To specify more clearly if it will work I need the script (without html)

vincevincevince

5:47 pm on Jul 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In general the only problem will be if they use the same name for the session variables (e.g. both use $_SESSION['admin']=true). If that was the case the logging in as admin on one would make you admin in another.