0

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.

user1831003
  • 184
  • 1
  • 4
  • 13

1 Answers1

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

Laurence
  • 58,936
  • 21
  • 171
  • 212
  • 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. – Laurence Dec 13 '12 at 02:15
  • You could serialize session anx store it in a file. But I always precer databases to files. Its much more stable – MAXIM Dec 13 '12 at 02:17
  • 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. – user1831003 Dec 13 '12 at 02:21
  • Try this http://stackoverflow.com/questions/2950355/set-session-in-database-in-php – Laurence Dec 13 '12 at 02:23