Hello again,
You guys saved me last time with something that was obvious, so I hope this isn't quite so stupidly simple.
I am trying to create code in PHP to record a visitor's IP as they visit a page. I would like to simply use the same code for each page and have the info dump into a MySQL table and database. Now I managed to stitch together a simple script that captured every hit to a page and add a new line for each page, however, I'm having trouble getting the unique IP one working.
code:
<?php
include( 'includes/header.php');
$vari = "SELECT id, page, date, ip, count, browser, referal from ip_hits";
$page = $vari['page'];
$pageip = $vari['ip'];
$count = $vari['count'];
$ip = getenv ("REMOTE_ADDR");
$httpref = getenv ("HTTP_REFERER");
$httpagent = getenv ("HTTP_USER_AGENT");
$update = "UPDATE ip_hits SET count=count + 1, date=now() WHERE page = '$PHP_SELF' && ip = '$ip'";
mysql_query($update);
if (($page <> $PHP_SELF) && ($pageip <> $ip)) {
$result = "INSERT INTO ip_hits VALUES ('', '$PHP_SELF', now(), '$ip', 1, '$httpagent', '$httpref')";
mysql_query($result);
}
?>
Now, the problem is probably very obvious to you all, however, when I use this code, it updates any table row that has both the page and the IP, which is exactly how I intended the code to work. However, it still adds a new line of code on each reload of the page. So my question is: What is wrong with my operators after the 'IF' statement that causes the code to add another row to the table? From my interpretation of the code, it should only insert a new row IF both the page AND ip are NOT in the same row.
Help! ... Please! ::grin::
Thank you all,
Dustin
P.S. - Again, my apologies about the ugly code, I do hope to eventually get better. ::grin::