I'm trying to create a little program that I can stick on my site that logs the information of each user on a daily basis. I got it so that it is inserting the information that I want (ip, time & date, referer, etc) However, even with my if statement that checks the IP address, date, and page they are viewing to the database, it is still adding them anyways. Here is the script:
<?
$ip = $_SERVER[REMOTE_ADDR];
$referer = $_SERVER[HTTP_REFERER];
$page = "http://www.myserver.net".$_SERVER[PHP_SELF];
$date = date("m-d-Y");
$time = date("H:i:s");
$query1 = mysql_query("SELECT * FROM stats");
while ($row = mysql_fetch_array($query1))
{
if($ip = $row[user_ip] AND $date = $row[date] AND $referer = $row[referer])
{
echo "<center><font size=2>ip logged</font></center>";
die; //I've also tried to use "exit" here
}
}
$query2 = mysql_query("INSERT INTO stats VALUES('null','$ip','$time','$date','$referer','$page')");
if($query2)
{
echo "<center><font size=2>ip logged</font></center>";
}
else
{
echo "There was a problem with the statistics" . mysql_error();
}
?>
Any idea why it isn't working?