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 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"); }} 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'); } 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?... 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. 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
Archived
This topic is now archived and is closed to further replies.