Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP /SESSION: Login one per user?

Tags:

php

How can i do so only 1 can be online for the 1 user at the time? Idea ?

So you e.g can not login to User1 on one pc/browser and then on the other pc/browser login to User1?

I have my communitysystem in PHP, and it stores in sessions..

like image 724
Karem Avatar asked Sep 04 '10 19:09

Karem


People also ask

Is PHP SESSION per user?

The session is unique to whomever has that session ID, which is determined by the cookie. Yes, it's unique to each user. Variable scope means nothing here. Each request handled by PHP is isolated and has its own global scope (unless you have built your own daemon or something).

How many sessions can PHP handle?

PHP sessions are (by default) file based, so you can have as many of them as can fit on your server's disk. Save this answer. Show activity on this post. No, this exactly means that there can't be more than 30 simultaneous connections.


1 Answers

You could store the session ID (and last access time) in a database, and reject login attempts for users with different session IDs if the last-access time is too recent(say, within the past 20 minutes). Clear the ID on logout, of course.

Note, though, if a user closes their browser without logging out and then reopens it, they may well be locked out for a while (the 20 minutes above, or whatever interval you decide on), since they won't have the matching session cookie anymore.

like image 72
cHao Avatar answered Oct 15 '22 00:10

cHao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!