ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: krapalm ที่ 05 พฤษภาคม 2010, 15:06:08



หัวข้อ: จะเช็ค bot ที่เข้ามาเก็บข้อมูลแต่ Error
เริ่มหัวข้อโดย: krapalm ที่ 05 พฤษภาคม 2010, 15:06:08
ผมจะเช็ค bot ที่เข้ามาเก็บข้อมูลโดยใช้ Code จากเว็บนี้แหละครับ แต่พอไปวางมันขึ้น error ตามภาพ
(http://lh5.ggpht.com/_Sp8Go_h3zLw/S-EmciFZZCI/AAAAAAAAHp4/OrhWOwgFrbw/Capture.PNG)
code
โค๊ด:
<?php
error_reporting
(E_ALL);

//file_put_contents on php4
if (!function_exists(&#39;file_put_contents&#39;)) {
    
function file_put_contents($filename$data) {
        
$f = @fopen($filename, &#39;w&#39;);
        
if (!$f) {
            return 
false;
        } else {
            
$bytes fwrite($f$data);
            
fclose($f);
chmod($filename0666);
            return 
$bytes;
        }
    }
}


$bot "";
if (
strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;Yandex&#39;)){ $bot=&#39;Yandex&#39;;}
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;Googlebot&#39;)){$bot=&#39;Google&#39;;}
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;Mediapartners-Google&#39;)){$bot=&#39;Mediapartners-Google (Adsense)&#39;;}
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;Slurp&#39;)){$bot=&#39;Hot Bot search&#39;;}
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;WebCrawler&#39;)){$bot=&#39;WebCrawler search&#39;;}
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;ZyBorg&#39;)){$bot=&#39;Wisenut search&#39;;}
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;scooter&#39;)){$bot=&#39;AltaVista&#39;;}  
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;StackRambler&#39;)){$bot=&#39;Rambler&#39;;}  
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;Aport&#39;)){$bot=&#39;Aport&#39;;}  
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;lycos&#39;)){$bot=&#39;Lycos&#39;;}  
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;WebAlta&#39;)){$bot=&#39;WebAlta&#39;;}
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;yahoo&#39;)){$bot=&#39;Yahoo&#39;;}
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;msnbot&#39;)){$bot=&#39;msnbot1.0&#39;;}
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;ia_archiver&#39;)){$bot=&#39;Alexa search engine&#39;;}
else if (strstr($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;FAST&#39;)){$bot=&#39;AllTheWeb&#39;;}


//File bot cache
$file_bot "bot.txt";
$tdiff 3600 7// เปลี่ยนจาก 0 เป็น 7 ถ้า Server นอก (GMT) หรือเพิ่มลดได้ตามแต่ Time Zone อยู่ที่ได (GMT -12 ถึง GMT +13)


if(!file_exists($file_bot)) {
file_put_contents($file_botserialize(array()));
}

if(!empty(
$bot)) {
//Get old data
$bot_list unserialize(file_get_contents($file_bot));
$day date("d/m/Y",time() + $tdiff);
$time date("H:i:s",time() + $tdiff);
$ip $_SERVER[&#39;REMOTE_ADDR&#39;];

$bot_list[$bot] = array($day$time$ip);

//Save new data
file_put_contents($file_botserialize($bot_list));
}
 

$thai_month[1] = "มกราคม";
$thai_month[2] = "กุมภาพันธ์";
$thai_month[3] = "มีนาคม";
$thai_month[4] = "เมษายน";
$thai_month[5] = "พฤษภาคม";
$thai_month[6] = "มิถุยายน";
$thai_month[7] = "กรกฎาคม";
$thai_month[8] = "สิงหาคม";
$thai_month[9] = "กันยายน";
$thai_month[10] = "ตุลาคม";
$thai_month[11] = "พฤศจิกายน";
$thai_month[12] = "ธันวาคม";

function 
showbot($botname) {
global $bot_list$file_bot$thai_month$tdiff;
if(!isset($bot_list)) {
$bot_list unserialize(file_get_contents($file_bot));
}

if(!isset($bot_list[$botname])) {
$out "<dd><strong>บอทยังไม่ได้มาเก็บข้อมูล</strong></dd>";
} else {
list($day$month$year) = explode("/",$bot_list[$botname][0]);
$month number_format($month);
list($hour$minute$second) = explode(":",$bot_list[$botname][1]);
$ip $bot_list[$botname][2];

$out "<dd>- บอท ".$botname ." ($ip) ";
if(date(&#39;d/m/Y&#39;,time()+$tdiff) == $bot_list[$botname][0]){
$out .= " มา วันนี้";
}else{
$out .=" มา เมื่อวันที่ ".$day." ".$thai_month[$month]." ". ($year+543);
}
$out .= " เวลา "$hour".".$minute." น.</dd>";
}
return $out;
}

//Show last bot
echo showbot(&#39;Google&#39;);
echo showbot(&#39;Alexa search engine&#39;);
echo showbot(&#39;Hot Bot search&#39;);
echo showbot(&#39;msnbot1.0&#39;);
?>

แล้วแทรกสคลิปนี้ลงใน footer
โค๊ด:
{php}include('/home/krapalmc/domains/krapalm.com/public_html/bookmarks/checkvbot.php');{/php}


หัวข้อ: Re: จะเช็ค bot ที่เข้ามาเก็บข้อมูลแต่ Error
เริ่มหัวข้อโดย: เก๋าลัดคุง ที่ 05 พฤษภาคม 2010, 15:14:27
file_get_contents   น่าเกิดจากระบุบ path ผิดหาไฟล์ไม่เจอครับ


หัวข้อ: Re: จะเช็ค bot ที่เข้ามาเก็บข้อมูลแต่ Error
เริ่มหัวข้อโดย: krapalm ที่ 05 พฤษภาคม 2010, 15:57:54
file_get_contents   น่าเกิดจากระบุบ path ผิดหาไฟล์ไม่เจอครับ

pังหาไม่เจอเลยครับว่าเกิดจากตรงไหน


หัวข้อ: Re: จะเช็ค bot ที่เข้ามาเก็บข้อมูลแต่ Error
เริ่มหัวข้อโดย: monthonsite ที่ 05 พฤษภาคม 2010, 16:29:36
bot.txt chmod เป็น 777 หรือยัง


หัวข้อ: Re: จะเช็ค bot ที่เข้ามาเก็บข้อมูลแต่ Error
เริ่มหัวข้อโดย: ชนเผ่าอาข่า ที่ 05 พฤษภาคม 2010, 16:29:49
file_get_contents   น่าเกิดจากระบุบ path ผิดหาไฟล์ไม่เจอครับ


pังหาไม่เจอเลยครับว่าเกิดจากตรงไหน


ลองทำตามกระทู้นี้ดูครับ

http://www.thaiseoboard.com/index.php/topic,56232.160.html


หัวข้อ: Re: จะเช็ค bot ที่เข้ามาเก็บข้อมูลแต่ Error
เริ่มหัวข้อโดย: krapalm ที่ 05 พฤษภาคม 2010, 17:32:41
bot.txt chmod เป็น 777 หรือยัง

ทำแล้วครับ ที่นี้ไม่ขึ้นอะไรเลย อาจจะเป็นไปได้ว่าบอทยังไม่มาเพราะพึ่งทำเสร็จใหม่ๆ ครับ


หัวข้อ: Re: จะเช็ค bot ที่เข้ามาเก็บข้อมูลแต่ Error
เริ่มหัวข้อโดย: krapalm ที่ 05 พฤษภาคม 2010, 17:34:58
file_get_contents   น่าเกิดจากระบุบ path ผิดหาไฟล์ไม่เจอครับ


pังหาไม่เจอเลยครับว่าเกิดจากตรงไหน


ลองทำตามกระทู้นี้ดูครับ

[url]http://www.thaiseoboard.com/index.php/topic,56232.160.html[/url]

ทำแล้วครับ ที่นี้ไม่ขึ้นอะไรเลย


หัวข้อ: Re: จะเช็ค bot ที่เข้ามาเก็บข้อมูลแต่ Error
เริ่มหัวข้อโดย: กระเทยหัวล้าน ที่ 05 พฤษภาคม 2010, 20:52:23
ลองดูการเก็บ bot แบบเว็บนี้ซิ http://www.xn--c3c2aex8b9c7a8cn8d.com/