Click to See Complete Forum and Search --> : blocking robots from hit counter


wwonder
01-09-2008, 11:37 AM
hi

i have a hit counter that counts unique ip addresses i have worked out how to block my ip address so that whilst designing i do not add to the counter but how would i block google robots etc from increasing the counter - code is as follows:

<?
// includes connection file
include("dbconnect.inc.php");

$ip = $_SERVER['REMOTE_ADDR'];
$date = date('d.m.Y');
$block = "195.93.21..*";

$MySql = "SELECT * FROM counter WHERE ip = '$ip' AND date = '$date';";
$get = mysql_query($MySql) or die(mysql_error());

if (ereg($block, $ip)) {

}else{
// Counts the rows found
if(mysql_num_rows($get)==0) {
// If no rows where found
$select = mysql_query("INSERT INTO counter (ip, date, hits) VALUES ('$ip', '$date', '1')");
// Inserts into the database, there ip and date of visit
} else {
// If they have been
$hit = mysql_fetch_array($get);
// selects the data from the database

$hits = $hit['hits'] + 1;

// Adds one onto current hit counter
$select = mysql_query("UPDATE counter SET hits = '$hits' WHERE ip = '$ip' AND date = '$date'");
// Updates Database with there new hit count
}}

?>

thanks

blue-eye-labs
01-09-2008, 12:07 PM
just google for google robots' IP, I'm sure they've documented it somewhere.
Never mind, it apparently changes... see here:
http://www.google.com/support/webmasters/bin/answer.py?answer=33577&topic=8460

Apparently you use the user-agent (Googlebot)