forked from tisuchi/webbotchecker
/
webbotchecker.php
66 lines (52 loc) · 1.81 KB
/
webbotchecker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* @ WebBotChecker
* Author : tisuchi
* Email : tisuchi@gmail.com
* URL : http://www.tisuchi.com
*
* ----------------------------------------------------------
* This class will identify whether the current user is real
* human or bot.
*/
class WebBotChecker {
protected $botArrayCheck;
function __construct() {
//array to set the bot name and for further checking. If you want, then you can manully add more bot name.
$botArrayName = array (
'googlebot' => '/Googlebot/',
'msnbot' => '/MSNBot/',
'slurp' => '/Inktomi/',
'yahoo' => '/Yahoo/',
'askjeeves' => '/AskJeeves/',
'fastcrawler' => '/FastCrawler/',
'infoseek' => '/InfoSeek/',
'lycos' => '/Lycos/',
'yandex' => '/YandexBot/',
'geohasher' => '/GeoHasher/',
'gigablast' => '/Gigabot/',
'baidu' => '/Baiduspider/',
'spinn3r' => '/Spinn3r/'
);
/**
* Check whether the requester is bot or not
*/
if( true == isset( $_SERVER['HTTP_USER_AGENT'] )) {
$this->botArrayCheck = preg_filter( $botArrayName, array_fill( 1, count( $botArrayName ), '$0' ), array( trim( $_SERVER['HTTP_USER_AGENT'] )));
}
}
public function getMyBot() {
/**
* return if the request can identified the bot or not
*/
return ( true == is_array( $this->botArrayCheck ) && 0 < count( $this->botArrayCheck )) ? $this->botArrayCheck[0] : 'Sorry! Its not a bot. ';
}
/**
* [isThatBot description]
* @return boolean [This function will will increment the record of user if the user is not a bot.]
*/
function isThatBot() {
//checking again if the bot is requested.
return ( true == is_array( $this->botArrayCheck ) && 0 < count( $this->botArrayCheck )) ? 1 : 0;
}
}