0

I found a crawl detection script on the internet that works great. But at the moment I only have Googlebot. I'm trying to add YahoosLurp, and Ask Jeeves, and any other popular web crawler. PHP is definetly my weakness

Heres the script

<?php

$useragent = $_SERVER["HTTP_USER_AGENT"];

if (stripos($useragent,"Googlebot"))
{
 //Found! Create file
 $file = fopen("crawled.txt","a");
 fwrite($file,"You've been crawled\n");
}

?>

Its saved in a text file called crawled.txt

Im trying to add extra crawlers to the script, with the date.

Edited by JayGeePee: Didn't add code brackets

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by mbhanley
0

Here you go use this and then include the text files into a textarea it works pretty sweet. Hope this helps.

<?php

/* 
Search engine spiders
Yahoo! Slurp
Msnbot
Googlebot
Ask Jeeves
*/

$useragent = $_SERVER["HTTP_USER_AGENT"];
$ref = $_SERVER['HTTP_REFERER'];
$host = $_SERVER['HTTP_HOST'];
$ip = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y H:i:s');


if (strpos($useragent,"Firefox"))
{
	//found! create file
	$file = fopen("./crawldetector/Visitor.txt","a");
	fwrite($file,""."\nVisitor Stat: \n"."UserAgent: $useragent"."\n"."Date & Time: $date"."$ref \n"."$ip\n"."$host"."\n ----------------------- \n"."");
}


if (strpos($useragent,"Yahoo! Slurp"))
{
	//found! create file
	$file = fopen("./crawldetector/Yahoo.txt","a");
	fwrite($file,""."\nCrawl Stat: \n"."UserAgent: $useragent"."\n"."Date & Time: $date"."$ref \n"."$ip\n"."$host"."\n ----------------------- \n"."");
}

if (strpos($useragent,"Googlebot"))
{
	//found! create file
	$file = fopen("./crawldetector/Googlebot.txt","a");
	fwrite($file,""."\nCrawl Stat: \n"."UserAgent: $useragent"."\n"."Date & Time: $date"."$ref \n"."$ip\n"."$host"."\n ----------------------- \n"."");
}

if (strpos($useragent,"Msnbot"))
{
	//found! create file
	$file = fopen("./crawldetector/Msnbot.txt","a");
	fwrite($file,""."\nCrawl Stat: \n"."UserAgent: $useragent"."\n"."Date & Time: $date"."$ref \n"."$ip\n"."$host"."\n ----------------------- \n"."");
}

if (strpos($useragent,"Ask Jeeves"))
{
	//found! create file
	$file = fopen("./crawldetector/AskJeeves.txt","a");
	fwrite($file,""."\nCrawl Stat: \n"."UserAgent: $useragent"."\n"."Date & Time: $date"."$ref \n"."$ip\n"."$host"."\n ----------------------- \n"."");
}


?>

Textarea's with the text files to include.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Crawler Stats</title>
</head>

<body>

<h4>Visitors</h4>
<textarea rows="10" cols="70">
<?php include('visitor.txt'); ?>
</textarea>

<br />
<h4>Google</h4>
<textarea rows="10" cols="70">
<?php include('googlebot.txt'); ?>
</textarea>

<br />
<h4>Yahoo</h4>
<textarea rows="10" cols="70">
<?php include('Yahoo.txt'); ?>
</textarea>

<br />
<h4>Bing</h4>
<textarea rows="10" cols="70">
<?php include('Msnbot.txt'); ?>
</textarea>

<br />
<h4>Ask Jeeves</h4>
<textarea rows="10" cols="70">
<?php include('AskJeeves.txt'); ?>
</textarea>

</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.