OK, I have a counter setup for my site. It reads the IP of the user, checks it against a database and if the IP address doesn't exist in the db, it'll add it.
Here's my function to check the IP:
I was using just "$ip = getenv("REMOTE_ADDR");" to grab the IP, but someone from this forum (sonofslim??) suggested I use this series of if/elseif/else statements because it was better.
I'm getting some odd results though. When I check the mysql db, some odd looking IPs include:
10.77.45.179, 210.11.178.71 (saved in one cell of the table)
172.17.246.191, 193.
202.0.43.53, 203.97.
205.138.21.143, unknown
207.44.248.42, 200.1
etc, etc, etc...
It looks like it's grabbing 2 IP addresses when it does the check. So I ask... what's the dilly, yo??!
Thanks.
EDIT
Here's my insert function:
Here's my function to check the IP:
PHP:
function ipcheck() {
global $username, $password, $database, $table, $ip, $ipstatus;
if(getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
}
elseif(getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
}
else {
$ip = getenv("REMOTE_ADDR");
}
$db = mysql_connect("localhost", "$username", "$password");
mysql_select_db($database, $db) or die("Invalid server or user.");
//check to see if the IP exists
$grabip="select * from $table where ipaddy='$ip'";
$ipresult=mysql_query($grabip) or die("select fails");
$ipstatus=mysql_num_rows($ipresult);
}
I'm getting some odd results though. When I check the mysql db, some odd looking IPs include:
10.77.45.179, 210.11.178.71 (saved in one cell of the table)
172.17.246.191, 193.
202.0.43.53, 203.97.
205.138.21.143, unknown
207.44.248.42, 200.1
etc, etc, etc...
It looks like it's grabbing 2 IP addresses when it does the check. So I ask... what's the dilly, yo??!
Thanks.
EDIT
Here's my insert function:
PHP:
if ($ipstatus==0)
{
$ipinfo= "insert into $table (ipaddy) values ('$ip')";
$insertip = mysql_query($ipinfo);
}