As an example, assume you've created a table called Users and you have three columns:
Users:
ip_address,
count,
admin_flag
The ip_address holds the ip addresses of visitors and administrators alike.
The count holds the count of the number of times a unique ip addresses has come to your site and has had their ip address parsed by your script.
The admin_flag holds either a "1" or a "0" to indicate if the ip_address is from a visitor (a "0") or from an administrator (a "1").
Here is the script that you can use. Obviously, as you develop this db and script, you'll want to collect more info than perhaps just an IP address and count. Post back if you have more problems. Else, mark this post "resolved".
<?php
$get_ip = $_SERVER['REMOTE_ADDR'];
$new_count = 0;
/* create query to select IP addresses and related info*/
$sql = "SELECT u.ip_address,
u.count,
u.admin_flag
FROM Users as u
WHERE u.ip_address = '$get_ip'";
$result = mysql_query($sql, $connection)
or die("<p>Couldn't execute query :".mysql_error());
$num_of_matches = mysql_num_rows($result);
if ($num_of_matches > 0) // check for return visitors
{
$row = mysql_fetch_array($result);
$remote_ip = $row['ip_address'];
$new_count += $row['count'];
if ($row['admin_flag'] == 0)
{ /* this is a return visitor who is not using admin IP addr
so insert the $new_count into the User table*/
$sql = "INSERT into Users
(count)
VALUES
('$new_count')
WHERE Users.ip_address = '$get_ip'
LIMIT 1";
$result = mysql_query($sql, $connection)
or die("<p>Couldn't perform insert on Users table :".mysql_error());
}
else // this is a new visitor
{
$new_count = 1;
// since he is not an administrator, set his $admin_flag to 0:
$admin_flag = 0;
// insert his ip address into the Users table
$sql = "INSERT into Users
VALUES
('$get_ip', '$new_count', '$admin_flag')";
$result = mysql_query ($sql, $connection)
or die("<p>Couldn't insert new visitor IP address into Users table: ".mysql_error());
}
?>