|
 |
|
โค้ดที่ใช้ตรวจสอบว่า บอท ตัวไหนมาเก็บข้อมูลที่เว็บเราแบบนี้ถูกหรือปล่าวครับ |
|
 |
|
|
 |
 |
|
โค้ดที่ใช้ตรวจสอบว่า บอท ตัวไหนมาเก็บข้อมูลที่เว็บเราแบบนี้ถูกหรือปล่าวครับ พี่ๆ ช่วยดูทีครับ
หน้า bot.php
Code (PHP)
<?
if (strstr($_SERVER['HTTP_USER_AGENT'], 'Yandex')){ $bot='Yandex';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Googlebot')){$bot='Google';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Mediapartners-Google')){$bot='Mediapartners-Google (Adsense)';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Slurp')){$bot='Hot Bot search';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'WebCrawler')){$bot='WebCrawler search';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'ZyBorg')){$bot='Wisenut search';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'scooter')){$bot='AltaVista';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'StackRambler')){$bot='Rambler';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Aport')){$bot='Aport';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'lycos')){$bot='Lycos';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'WebAlta')){$bot='WebAlta';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'yahoo')){$bot='Yahoo';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'msnbot')){$bot='msnbot/1.0';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'ia_archiver')){$bot='Alexa search engine';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'FAST')){$bot='AllTheWeb';}
if($bot !=""){
$tdiff = 3600 * 0; // เปลี่ยนจาก 0 เป็น 7 ถ้า Server นอก (GMT) หรือเพิ่มลดได้ตามแต่ Time Zone อยู่ที่ได (GMT -12 ถึง GMT +13)
$file = "bots.txt";
$day = date("d/m/Y",time() + $tdiff);
$time = date("H:i:s",time() + $tdiff);
$ip = $_SERVER['REMOTE_ADDR'];
$fh = fopen($file, "w");
fwrite($fh, "$day|$time|$bot|$ip");
fclose($fh);
}
$month[1] = "มกราคม";
$month[2] = "กุมภาพันธ์";
$month[3] = "มีนาคม";
$month[4] = "เมษายน";
$month[5] = "พฤษภาคม";
$month[6] = "มิถุยายน";
$month[7] = "กรกฎาคม";
$month[8] = "สิงหาคม";
$month[9] = "กันยายน";
$month[10] = "ตุลาคม";
$month[11] = "พฤศจิกายน";
$month[12] = "ธันวาคม";
$file = "bots.txt";
if(file_exists($file)) {
$fh = fopen($file, 'r+');
$s = filesize($file);
if($s == 0) {
$out = "<strong>บอทยังไม่ได้มาเก็บข้อมูล</strong>";
}else{
$contents = fread($fh, $s);
fclose($fh);
$info = explode("|",$contents);
$day = explode("/",$info[0]);
$m = number_format($day[1]);
$tm = explode(":",$info[1]);
$agent = $info[2];
$ip = $info[3];
$out = "<strong>บอทตัวล่าสุดที่เข้ามาเก็บข้อมูล คือ </strong><br /><strong> ".$agent ." ($ip) ";
if(date('d',time()) == $day[0]){
$out .= " วันนี้";
}else{
$out .=" เมื่อวันที่ ".$day[0]." ".$month[$m]." ". ($day[2]+543);
}
$out .= " เวลา ". $tm[0]. ".".$tm[1]." น.</strong>";
}
echo $out;
}
?>
หน้าที่เรียกดู bot.txt
<?php
include('/domains/xxx.com/public_html/bot.php');
?>
พี่ๆ ช่วยดูให้หน่อยนะครับ ผิดตรงไหนบอกด้วยนะครับ ผมจะได้แก้ไขให้ถูกต้อง
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2010-12-28 15:29:15 |
By :
เดกอ่อนหัด |
View :
2149 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถูกแล้วครับ มันเป็นอะไรหรอครับ ถ้าให้เดาน่าสคริปไม่ทำงานหรอครับ
วิธีใช้ สร้างไฟล์ดังนี้
1. check_bot.php << ให้เอาโค้ดทั้งหมดไปใส่ไว้ในไฟล์นี้นะครับ
2. bots.txt << สร้างไฟล์ text ขึ้นมา 1 อัน เพื่อที่เก็บรายการบอทแต่ละตัวและสคริปจะได้ดึงไปแสดงที่เว็บได้ อย่าลืม ทำ chmod 777 ที่ไฟล์ด้วยนะครับ
เอาไฟล์งานกับ text file ไปไว้ Root ของ server เอาไปไว้ที่เดียวกับไฟล์ index.php ก้ได้นะครับ
เรียกใช้ไฟล์ check_bot.php โดยการ include เอา ไม่ต้องเรียกแบบเต็มยศแบบนี้นะครับ include('/domains/xxx.com/public_html/bot.php');
|
 |
 |
 |
 |
Date :
2010-12-28 15:52:52 |
By :
somparn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เวลาเปิดดู เปิดที่ไฟล์ bot.txt ใช่หรือปล่าวครับ แนะนำด้วยครับ
|
 |
 |
 |
 |
Date :
2010-12-28 17:16:29 |
By :
เดกอ่อนหัด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เวลาตวจสอบว่า บอท ไหนเข้ามาเว็บของเราทำยังงัยอ่ะครับ ช่วยหน่อยนะครับ
|
 |
 |
 |
 |
Date :
2010-12-28 21:36:38 |
By :
เดกอ่อนหัด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|