1

I'm storing some user information in session so I don't have to query the database every single time user changes page. What if this user uses multiple browsers/computers and olders sessions have invalid data now? How do I keep them in sync? Logging out the older sessions of the user is fine, but I would like to avoid writing session info to db, if possible.

I do realize it's a fairly common problem, but I couldn't come up with right stuff after googling.

1 Answer 1

1

Store the session in a database for each specific user.

Then each time the users access your site (regardless of which browser) - all the information is always in one location, and you dont have to do any fancy 'sync' stuff.

Note: they will still have to 'login' from each different browser. During the login process, you will need to check if a session already exists in the database for that user. If it does, you need to attach this new login to that session (rather than create a new one).

Sign up to request clarification or add additional context in comments.

4 Comments

Well - you cant store the session in the cookie on each browser - because you will have no way to 'sync' the data reliably. So it needs to be file/database storage - i.e. a centralised location on your server.
You could serialize session anx store it in a file. But I always precer databases to files. Its much more stable
any link for the process you're describing (about storing it in database)? I am a little stuck with searching for this as I mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.