Jump to content

Recommended Posts

Hey guys, I am using session variables in order to insert the username into the database when the user submits a form. I was just wondering as I don't fully understand session variables could this cause any problems? For example if one user logs in and then another will the first users session vars be overwritten?

 

(I am only making a localhost site which is run locally, so if I did this on my machine logging in two different users one in firefox one in ie would this also be ok?)

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/62759-session-variable-question/
Share on other sites

The session variables are independent of users and browsers. The session will stay alive for the lifetime of the browser (unless you use your own session scheme). But when a browser closes that user's session is wiped out essentially.

 

The only concern you might have is session hi-jacking, which is only a concern on Shared hosting.

 

You should be fine. Sessions are independent of each other.

another question I have about session variables would be if for example my username was 'testUsername' and I logged in with that username and didn't logout using session_destroy and someone else used the login page with a shorter username for example 'test' would the session store the username as test or because it didn't logout properly would it be a jumble of both usernames? ans does this apply to all session variable? thanks.

another question I have about session variables would be if for example my username was 'testUsername' and I logged in with that username and didn't logout using session_destroy and someone else used the login page with a shorter username for example 'test' would the session store the username as test or because it didn't logout properly would it be a jumble of both usernames? ans does this apply to all session variable? thanks.

 

No, session variables are unique to user/browser session.

 

If someone was using the same browser and logged out and then logged back in, the session data should be overwritten. But you should kill the session data when a user logs out.

 

Also session data usually has a life span of 20 minutes default I believe, something like that. I am not sure how closely PHP follows it but yea.

 

The key is that sessions are completely independent of each other as long as the user is using a different computer/browser. I generally store login information in cookies hashed up to verify that against the DB, so the cookie keeps the user logged in and not sessions for that exact reason of a browser closing. Anyhow I think you are worrying too much. Once again, sessions are completely independent of each other.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.