<?php
/**
* Check if the visitor is a robot
* Copyright: 2015 Ing. Rubén Elizondo C.
* All rights reserved
* This code is open source and released under GPL licence terms
* If you find this code useful, please post comment on PHP Classes
* or at http://hostingcrafters.blogspot.mx/
*/
class CheckBot
{
private $robot='N';
private $useragent;
public static function check_bot($ua){
$useragent=strtolower($ua);
if(strpos($useragent,'bot')>0 || strpos($useragent,'Bot')>0 || strpos($useragent,'www.facebook.com')>0)
{
$robot='Y';
}
return $robot;
}
}
/**
* Test script
* If you want to check if the script is working just uncomment the test line
* and comment that that gets the UA from $_SERVER
*/
//$ua='test if robot';
//$ua='test if roBot';
//$ua='test if spider from www.facebook.com';
// also you can add here more known bots / spiders and modify the check_bot method accordingly
$ua=$_SERVER['HTTP_USER_AGENT'];
if(CheckBot::check_bot($ua)!='Y')
{
echo 'Im not a Robot';
}
else
{
echo 'Haha im a Robot!';
}
?>
|