Jump to content

enforce one login per username


classic

Recommended Posts

I have username demo password demo I'm mysql tables

 

I need to only  allow one session for this. Subsequent users get "already logged in try later"

If I set a flag in the database    logged in true I could test for this and set to false when logged our. If the client machine dies I would be left with logged in as true 

 

What is the best way please

Link to comment
https://forums.phpfreaks.com/topic/119110-enforce-one-login-per-username/
Share on other sites

Jus add to your functions script

 

$now = time() + 300;

$query = "UPDATE users SET activity='$now' WHERE username = '$username' LIMIT 1";

mysql_query($query);

 

And for login

 

$time = time();

$query = "SELECT activity FROM users WHERE username='$user' AND password='$pass' LIMIT 1";

$result = mysql_query($query);

$num = mysql_numrows($result);

 

if ($num != 0){

 

$row = mysql_fetch_row($result);

$activity = $row[0];

 

if ($activity > $time){

 

echo "You have already been active within the past 5 minutes, please try again in a few minutes.";

 

}else{

 

$_SESSION['username'] = $user;

Header("Location: blah.blah");

 

}}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.