Jump to content

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");

 

}}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.