PHP Classes

File: bot-class.php

Recommend this page to a friend!
  Classes of Ruben Elizondo   Bot Class   bot-class.php   Download  
File: bot-class.php
Role: Example script
Content type: text/plain
Description: Check if the visitor is a robot
Class: Bot Class
Simple check to see if the current user is a robot
Author: By
Last change: commented a test line and uncommented another
Date: 9 years ago
Size: 1,116 bytes
 

Contents

Class file image Download
<?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!';
        }


?>