Jump to content
  • Advertisement
Sign in to follow this  
iNoMore

Keeping track on user in a PHP Server

This topic is 1904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

 

So after my last post conclusions, I decided on a PHP based server for my game

the server is pretty much done, the only problem is, that I have no idea how to keep track on logged users

 

I want to make sure that the same username is not used at the same time from different computers

 

At first I thought on saving a session key in the database and delete it when logging out, but what if the client crashed, or the connection was reset at the user`s end, I cant know when the user was disconnected

and I cant know how long a game session will last

 

I hope you can point me at the right direction,

Thanks!!

Share this post


Link to post
Share on other sites
Advertisement
A typical approach is to have a fresh login invalidate all previous sessions belonging to that user. This avoids the problems you mentioned, as the new login will always be allowed, but multiple accounts will keep logging one another out.

Share this post


Link to post
Share on other sites

One common way to implement this is to store sessions, and the-session-for-a-user, in memcache. The session should contain the user it belongs to.

 

Thus, when receiving a session cookie, the server reads the session out of memcache, if it's not there the session is invalid.

If it's there, then the server reads the current-session-for-user out of memcache, and if that is not the current session id, then the incoming session has been invalidated by another login.

If it's there, and the current session stored for the user matches the session ID, then it's the latest session and you should continue processing. The first thing you might want to do is extend the session and user key time-to-lives.

 

When logging in, you generate a session ID. You write this session ID as "the current session" for the user, using the user ID as key. Then you write the logged-in session information (including user information) to the session, using the session ID as key. Use keys with expiry time that's whatever you want for your session idle length -- say, half an hour, or thirty days, or whatever.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!