Jump to content

1 logged in at a time


desithugg

Recommended Posts

Umm im having trouble logging in only 1 person at a time in one account i was thinking for like a week now and this is what i came up with
[code]
$stime=date("U")-0;
$ltime=date("U")-60;
$ipcheck = $_SERVER["REMOTE_ADDR"];
mysql_connect("localhost", $my_sql_password, $my_sql_username) or
   die("Could not connect: " . mysql_error());
mysql_select_db("osiris_thugg");

$result = mysql_query("SELECT time FROM online where username = '$user_currently_loged' && ip = '$ipcheck'");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}
$row = mysql_fetch_row($result);
$loggin = $row[0];
if($loggin == "")
{
mysql_query("INSERT INTO online
(username, ip, time) VALUES ('$user_currently_loged','$ipcheck','$stime') ")
or die(mysql_error()); 
}
mysql_query("update online set time = '$stime' where username = '$user_currently_loged'")
or die(mysql_error());
$result = mysql_query("SELECT count(time) FROM online where username = '$user_currently_loged' and time > '$ltime'");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}
$row = mysql_fetch_row($result);
$howmany = $row[0];
echo"There are more than 1 person(s) logged in this account at the moment";
include("bottom.php");
exit;
}
[/code]

What this code basically does is checks if the ip,username combonation already exists if it does exist it updates the previous record(time) if not it inserts a new rows(username,ip,time) and than the last query checks how many unique ips have been active in that account in the past 60 seconds but the problem im having is its not only counting the ones active in the last 60 secs its counting all the ips that have logged in so people keep having the error where it says there are more than 1 person(s) are people logged in this account.
Link to comment
Share on other sites

o.o nvm i just saw the problem
[code]mysql_query("update online set time = '$stime' where username = '$user_currently_loged'")
or die(mysql_error());
[/code]

whats happening is it is updating all the ips that have logged in the account with the new time so thats why the error keeps coming up.
Link to comment
Share on other sites

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.