Jump to content

Anti-bot list added to my counter


jmr3460

Recommended Posts

I just added a couple of lines that I hope will stop the bots and spiders from being counted. I just don't know if when I exit will it kill the script successfully, and not count them.

Here is the code:

 

<?php
include("db_in.php");
$table = "table_name";
$ip = getenv('REMOTE_ADDR');
$date = date("M-d-Y h:i:s", time()+3600);
$browser = $_SERVER['HTTP_USER_AGENT'];
//a defined array with a list of bots in it, defined as $bot
include("botlist.php");
if ($browser == $bot[])
{ 
exit 
}
else{
if (!isset($_COOKIE['clean']))
{
setcookie("clean","cleantime",time()+7200,"/");
mysql_connect($host, $user, $pass);
mysql_select_db($database) or die(mysql_error());
mysql_query("INSERT INTO $table values('id','$ip','$date','$browser')") or die(mysql_error());
$data = mysql_query("SELECT id FROM $table ORDER BY id DESC LIMIT 1;");
$info = mysql_fetch_array($data);
$count = $info['id'];
}
else
	{
mysql_connect($host, $user, $pass);
mysql_select_db($database) or die(mysql_error());
$data = mysql_query("SELECT id FROM $table ORDER BY id DESC LIMIT 1;");
$info = mysql_fetch_array($data);
$count = $info['id'];
}
}
?>
<html>
<?php echo $count; ?>
</html>

Here is my botlist.php

<?php
$bot = array("YandexSomething/1.0",
"Baiduspider+(+http://www.baidu.com/search/spider.htm)",
"TurnitinBot/2.1 (http://www.turnitin.com/robot/crawlerinfo.html)",
"LinkWalker/2.0",
"Gigabot/3.0 (http://www.gigablast.com/spider.html)",
"Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)");
?>

Thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/161618-anti-bot-list-added-to-my-counter/
Share on other sites

A suggestion, the code that you use now doesn't work for general bots, ie. if a yahoo or a msn bot comes, it would not catch that, a better way is to match up more general ones:

$useragent = $_SERVER['HTTP_USER_AGENT'];
$result = false;
$searchengines = array("bot", "crawler", "spider", "google", "yahoo", "msn", "ask", "ia_archiver");
foreach ($searchengines as $searchengine) {
$match = "/$searchengine/i";
if (preg_match($match, $useragent)) {$result = true;}}
if ($result == true) {//counter don't count bot}

Ted

[/code]

Is this a

 

$searchengines = array("bot", "crawler", "spider", "google", "yahoo", "msn", "ask", "ia_archiver");

 

I just got the above code inserted so I did not get any warnings. Everything seems to count. I got this hit two minutes after I got it going.

 

Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ys

 

Here is how I inserted the code above. I did change one thing. I changed $useragent to $browser because this is what I used for my counter.

 

<?php
include("dbin.php");
$ip = getenv('REMOTE_ADDR');
$date = date("M-d-Y h:i:s", time()+3600);
$table = "home";
$browser = $_SERVER['HTTP_USER_AGENT'];
$result = "false";
$searchengines = array("bot", "crawler", "spider", "google", "yahoo", "msn", "ask", "ia_archiver");
foreach ($searchengines as $searchengine) {
$match = "/$searchengine/i";
if (preg_match($match, $browser)) {$result = true;}}
if ($result == true) {//Counter script here
	if (!isset($_COOKIE['clean']))
	{
		setcookie("clean","cleantime",time()+7200,"/");
		mysql_connect($host, $user, $pass);
		mysql_select_db($database) or die(mysql_error());
		mysql_query("INSERT INTO $table values('id','$ip','$date','$browser')") or die(mysql_error());
		$data = mysql_query("SELECT id FROM home ORDER BY id DESC LIMIT 1;");
		$info = mysql_fetch_array($data);
		$count = $info['id'];
		}
else
		{
mysql_connect($host, $user, $pass);
mysql_select_db($database) or die(mysql_error());
$data = mysql_query("SELECT id FROM $table ORDER BY id DESC LIMIT 1;");
$info = mysql_fetch_array($data);
$count = $info['id'];
}
}
?>

<html>
<?php echo $count; ?>
</html>

Everything seems to count but I think this is something I am trying  not to count.

 

Why will my anti bot code not work. I was thinking that as they get counted I can review my report page and add any bots to my list. I am hoping that eventually catch a very large majority of them. If this one works!

 

You can see my report file at http://www.arscna.org/print.php

 

Sorry this is such a long post.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.