user online duplicate checking
Posted: Sun Mar 14, 2004 12:22 pm
okok this doesnt differ much from a post earlier on but ok i have the script:
Right so everytime the user reload the page it will store a unix timestamp, an ip address and the page name in a new row. Is there anyway to stop duplicates from being entered into the database, i.e. if the users ip address already exists in one of the rows, skip the insert part so it then can count the number of rows 'correctly'?
cheers for any help,
chris.
Code: Select all
$server = "";
$db_user = "";
$db_pass = "";
$db = "";
$to_secs = 180;
$t_stamp = time();
$timeout = $t_stamp - $to_secs;
mysql_connect($server, $db_user, $db_pass) or die ("Useronline Database CONNECT Error");
mysql_db_query($db, "INSERT INTO userson VALUES ('$t_stamp','$REMOTE_ADDR','$PHP_SELF')") or die("Database INSERT Error");
mysql_db_query($db, "DELETE FROM userson WHERE timestamp<$timeout") or die("Database DELETE Error");
$result = mysql_db_query($db, "SELECT ip FROM userson WHERE file='$PHP_SELF'") or die("Database SELECT Error");
$user = mysql_num_rows($result);
echo $user;cheers for any help,
chris.