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.
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).