classic Posted August 11, 2008 Share Posted August 11, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/119110-enforce-one-login-per-username/ Share on other sites More sharing options...
Andy-H Posted August 11, 2008 Share Posted August 11, 2008 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"); }} Quote Link to comment https://forums.phpfreaks.com/topic/119110-enforce-one-login-per-username/#findComment-613305 Share on other sites More sharing options...
waynew Posted August 11, 2008 Share Posted August 11, 2008 Just check if the session has been set already if(isset($_SESSION['username'])){ header('Location: home.php'); } Quote Link to comment https://forums.phpfreaks.com/topic/119110-enforce-one-login-per-username/#findComment-613309 Share on other sites More sharing options...
Andy-H Posted August 11, 2008 Share Posted August 11, 2008 Doesn't that only check their browser?... Quote Link to comment https://forums.phpfreaks.com/topic/119110-enforce-one-login-per-username/#findComment-613310 Share on other sites More sharing options...
waynew Posted August 11, 2008 Share Posted August 11, 2008 Sorry I misread. Quote Link to comment https://forums.phpfreaks.com/topic/119110-enforce-one-login-per-username/#findComment-613312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.