Hi Everyone,
"How to identify a web crawler in PHP ?", Consider the following example;
PHP Function
function isBotRobot(){
$machStr="Google|Alexa|yahoo";
$agent = @$_SERVER["HTTP_USER_AGENT"];
$url = @$_SERVER["REQUEST_URI"];
if(preg_match($matchStr,$agent)){
$GLOBALS['isBotRobot'] = true;
}
}
Database Table
CREATE TABLE IF NOT EXISTS page_visits(
id int(10) unsigned NOT NULL AUTO_INCREMENT,
userAgent varchar(100) COLLATE utf8_general_ci DEFAULT NULL,
url varchar(100) COLLATE utf8_general_ci DEFAULT NULL,
regDate datetime DEFAULT NULL,
ipAdress varchar(15) CHARACTER SET utf8 DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE MyISAM;
PHP Control
if(preg_match($matchStr,$agent)){
$DB =& Loader::loadClass('db');
$sql= "INSERT INTO page_visits (userAgent,url,regDate,ipAdress) VALUES (?,?,NOW(),?)";
$DB->insert($sql,array($agent,$url,$ipAdress);
@$GLOBALS['isBotRobot'] = true;
}