pixelposeur
05-08-2006, 02:28 AM
I made a couple of fixes to the "book_visitor" function to NOT book search robots or RSS feed hits.
One could make this smarter by adding a new "robots" database that could be managed by the admin panel, but this is quick and easy and gets about 90% of the search robots that hit my blog.
Here are my changes to functions.php:
function is_robot($ua) {
$robotuas = array ( "slurp", "googlebot", "msnbot", "alta-vista",
"ArchitextSpider", "geckobot", "infoseek", "lycos", "newsfire",
"Bloglines", "Magpie", "OmniExplorer_Bot"
);
foreach ($robotuas as $bot) {
$pattern = "/$bot/i";
if (preg_match ($pattern, $ua)) {
return 1;
}
}
return 0;
}
function book_visitor($str)
{
// book a visitor
$datetime = gmdate("Y-m-d H:i:s",gmdate("U")+(3600 *
$cfgrow['timezone']));
$host = $_SERVER['HTTP_HOST'];
$referer = addslashes($_SERVER['HTTP_REFERER']);
// don't book a referer from self
$refererhost = parse_url($referer);
$refererhost = $refererhost['host'];
if($refererhost == $host)
{
$referer = "";
}
$ua = addslashes($_SERVER['HTTP_USER_AGENT']);
if (is_robot($ua)) {
return;
}
$ip = $_SERVER['REMOTE_ADDR'];
$ruri = addslashes($_SERVER['REQUEST_URI']);
// ### if cookie lastvisit not set, count the people!
if(!isset($_COOKIE['lastvisit']))
{
$query = "insert into $str(id,datetime,host,referer,ua,ip,ruri)
VALUES(NULL,'$datetime','$host','$referer','$ua',' $ip','$ruri')";
$result = mysql_query($query);
}
}
Also fixes to "index.php" so that it doesn't even attempt to book hits
that use the "x=***" URL since those are usually RSS or other non-"real" visitor hits.
index.php, lines 72-75
// book visitors
if (strtolower($cfgrow['visitorbooking']) !='no' && !isset($_GET['x'])) {
book_visitor($pixelpost_db_prefix."visitors");
}
One could make this smarter by adding a new "robots" database that could be managed by the admin panel, but this is quick and easy and gets about 90% of the search robots that hit my blog.
Here are my changes to functions.php:
function is_robot($ua) {
$robotuas = array ( "slurp", "googlebot", "msnbot", "alta-vista",
"ArchitextSpider", "geckobot", "infoseek", "lycos", "newsfire",
"Bloglines", "Magpie", "OmniExplorer_Bot"
);
foreach ($robotuas as $bot) {
$pattern = "/$bot/i";
if (preg_match ($pattern, $ua)) {
return 1;
}
}
return 0;
}
function book_visitor($str)
{
// book a visitor
$datetime = gmdate("Y-m-d H:i:s",gmdate("U")+(3600 *
$cfgrow['timezone']));
$host = $_SERVER['HTTP_HOST'];
$referer = addslashes($_SERVER['HTTP_REFERER']);
// don't book a referer from self
$refererhost = parse_url($referer);
$refererhost = $refererhost['host'];
if($refererhost == $host)
{
$referer = "";
}
$ua = addslashes($_SERVER['HTTP_USER_AGENT']);
if (is_robot($ua)) {
return;
}
$ip = $_SERVER['REMOTE_ADDR'];
$ruri = addslashes($_SERVER['REQUEST_URI']);
// ### if cookie lastvisit not set, count the people!
if(!isset($_COOKIE['lastvisit']))
{
$query = "insert into $str(id,datetime,host,referer,ua,ip,ruri)
VALUES(NULL,'$datetime','$host','$referer','$ua',' $ip','$ruri')";
$result = mysql_query($query);
}
}
Also fixes to "index.php" so that it doesn't even attempt to book hits
that use the "x=***" URL since those are usually RSS or other non-"real" visitor hits.
index.php, lines 72-75
// book visitors
if (strtolower($cfgrow['visitorbooking']) !='no' && !isset($_GET['x'])) {
book_visitor($pixelpost_db_prefix."visitors");
}