I do not understand PHP Sessions

Discussion in 'PHP' started by dpacmittal, Mar 10, 2009.

  1. dpacmittal

    dpacmittal New Member

    Joined:
    Mar 10, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    PHP sessions are used to store user information and pass that information to a group of pages. But where is the session information stored, on the user computer or the web server?

    Suppose I logged into a site. Now that site has my information stored in session. If another user logs in from another computer with his own username, does his information gets stored in a session and mine is removed or is there a array of sessions? I just dont understand the idea of session.
    If you didnt get what I am asking, we have same session variable for everyone. like $_SESSION['username'] is used for everyone in a site. If I log in my username is stored in that variable. If another user logs in, does his username replaces mine or is there a sort of array which stores all usernames.

    Hope you understood what I am asking.

    Any help would be appreciated.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    On the Server.

    Session is something which is one to one.

    That means if 2 people connect using the 2 different locations 2 sessions runs in the server.
     
  3. dpacmittal

    dpacmittal New Member

    Joined:
    Mar 10, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Thanks Shabbir for your reply.
    I researched some more about sessions and found out about session id. I got the idea.

    I am trying to make a chat script using php, ajax and mysql. If I use sessions for storing information how will I show who's online in a chat room? Is there a way to display all active sessions.
    Another way is storing online users' information in database. I can keep a logout button which would remove the user's record from database, but if the user closes the browser instead of logout button, then the record wont be deleted from table and he won't be able to log in again.
    Help me find a solution.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    No you need to have them into the database and then display it because displaying the sessionid can be a security flaw as well as of no use.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice