.htaccess เอาไม่อยู่ครับ ผมก็ลองมาแล้วเหมือนกัน
block ด้วย bot-agent มันไม่ได้ช่วยเท่าไร block มันด้วย IP มันก็เข้ามาได้อีก คิอมันแค่ crawl เข้าไปในเว็บเราไม่ได้ แต่มันยังสามารถ มาเข้ามาที่หน้าเว็บเราได้น่ะคับ งงมั้ยเนี่ย
คือเข้ามาวิ่งเล่นสนุกสนาน แต่ไม่เอาข้อมูลเว็บเรากลับไปทำประโยชน์ใช่มั้ยครับ
ถูกต้องละคับ คือมันกันไม่ให้มันเลื้อยไปต่อ แต่มันก็เข้ามาที่หน้าเว็บเราได้อยู่ดี
ขออนุญาต เสริมของคุณป๊อบให้นะครับ แบบที่ว่ามายังพอมีวิธีแก้ไขอยู่บ้าง ตามลิ้งก์
http://www.aomtalk.com/2010/11/build-your-own-bot-trap.html
กรทำงานของสคริปคือ จะป้องกันไม่ให้บอทที่ไม่สนใจคำสั่งใน robots.txt เข้ามาอีกเป็นครั้งที่สอง
- สร้างไฟล์ bad-bots.php ด้วยโค้ด
<?php
header("Content-type: text/html; charset=utf-8");
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
';
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>BAD BOTS DENIED</title>
</head>
<body>
<p>BAD BOTS DENIED</p>
<?php
// author: seven-3-five, 2006-09-04, seven-3-five.blogspot.com
//this script is the meat and potatoes of the bot-trap
// SERVER VARIABLES USED TO IDENTIFY THE OFFENDING BOT
$ip = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
//$request = $_SERVER['REQUEST_URI'];
//$referer = $_SERVER['HTTP_REFERER'];
$text = 'deny from ' . $ip . "\n";
$file = '.htaccess';
$good = Array('google',
'yahoo',
'msn',
//'',
);
$bb=0;
foreach ($good AS $gb) {
if (!strstr($agent, strtolower($gb)))
$bb++;
}
if ($bb==sizeof($good)) {
add_badbot($text, $file);
}
// Function add_bad_bot($text, $file_name): appends $text to $file_name
// make sure PHP has permission to write to $file_name
function add_badbot($text, $file_name) {
$handle = fopen($file_name, 'a');
fwrite($handle, $text);
fclose($handle);
}
?>
</body>
</html>
- ถ้าต้องการให้ส่งเมล์เตือนเมื่อมี bad bots เข้ามาให้ทำตามนี้
This file has been tested. However, it may be a good idea to check it by pasting it into Notepad. If you see any black squares, replace them with quote marks (“). If you want to send yourself an email every time the trap catches something, paste the following code into the file, just before the final ?>:
$subject = 'bad-bots';
$email = 'your_email@your_site.com'; //edit accordingly
$to = $email;
$message ='ip: ' . $ip . "\r\n" .
'user-agent string: ' . $agent . "\r\n" .
'requested url: ' . $request . "\r\n" .
'referer: ' . $referer . "\r\n"; // often is blank
$message = wordwrap($message, 70);
$headers = 'From: ' . $email . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Make sure to change
your_email@your_site.com to your actual email address.
- เพิ่มคำสั่งด้านล่างไปในไฟล์ robots.txt
User-agent: *
Disallow: /bad-bots.php
- เพิ่มลิ้งก์ที่อ้างอิงไฟล์ bad-bots.php ลงไปที่ footer ของเว็บเราแบบนี้ (เลือกเอาอันเดียวที่เราชอบ)
<a href=”http://www.mysite.com/bad-bots.php”><!– jangle-tacks –></a>
<a href=”http://www.mysite.com/bad-bots.php”><img src=”jangle-tacks.gif” height=”1″ width=”1″ border=”0″></a>
<a href=”http://www.mysite.com/bad-bots.php” style=”display: none;”>jangle-tacks</a>
<div style=”display: none;”><a href=”http://www.mysite.com/bad-bots.php”>jangle-tacks</a></div>
<a href=”http://www.mysite.com/bad-bots.php”></a>
<!– <a href=”http://www.mysite.com/bad-bots.php”>jangle-tacks</a> –>
<div style=”position: absolute; top: -250px; left: -250px;”><a href=”http://www.mysite.com/bad-bots.php”>jangle-tacks</a></div>
<a href=”http://www.mysite.com/bad-bots.php”><span style=”display: none;”>jangle-tacks</span></a>
<a href=”http://www.mysite.com/bad-bots.php”><div style=”height: 0px; width: 0px;”></div></a>
หลักการคือเวลาบอท วิ่งเข้ามาอ่านถ้าเป็นบอทปกติ จะต้องสนใจ robots.txt ก่อนอันดับแรกและทำตามคำสั่งนั้นๆ กรณีที่เจอบอท แบบที่คุณป๊อบว่ามันจะดื้อกับทุกๆคำสั่งแล้วจะวิ่งไปลิ้งก์ทุกลิ้งก์ที่มี พอมันวิ่งเข้าไปที่ bad-bots.php ก็จะถูกเก็บ ip และเขียนคำสั่งไปที่ .htaccess ป้องกันบอทนั้นๆเข้ามาอีกต่อไป