PHP judges whether the visitor is a spider or a common user
Source: Internet
Author: User
Prepare for formal SEO. the black chain code is still used, but it is a little special. of course, test whether it is feasible first. Get a PHP document to record whether the visitor is a spider or a common user. Specifically, it is based on php's $ _ SERVER [& amp; #39; HTTP_USER_AGENT & amp; #39;] to determine... syntaxHig is ready to start regular SEO. the black chain code is still used, but it is a little special. of course, test whether it is feasible first.
You need to get a PHP document to record whether the visitor is a spider or a common user. Specifically, it is determined based on php's $ _ SERVER ['http _ USER_AGENT '].
The code is as follows:
$ Tmp = $ _ SERVER ['http _ USER_AGENT '];
If (strpos ($ tmp, 'googlebot ')! = False ){
Echo 'Google ';
} Else if (strpos ($ tmp, 'baidider Ider ')> 0 ){
Echo 'Baidu ';
} Else if (strpos ($ tmp, 'Yahoo! Slurp ')! = False ){
Echo 'Yahoo ';
} Else if (strpos ($ tmp, 'msnbot ')! = False ){
Echo 'MSN ';
} Else if (strpos ($ tmp, 'sosospider ')! = False ){
Echo 'search ';
} Else if (strpos ($ tmp, 'yodaobot ')! = False | strpos ($ tmp, 'outfoxbot ')! = False ){
Echo 'youdao ';
} Else if (strpos ($ tmp, 'sogou web spider ')! = False | strpos ($ tmp, 'sogou Orion spider ')! = False ){
Echo 'sogou ';
} Else if (strpos ($ tmp, 'fast-webcrawler ')! = False ){
Echo 'alltheweb ';
} Else if (strpos ($ tmp, 'gaisbot ')! = False ){
Echo 'gaais ';
} Else if (strpos ($ tmp, 'ia _ archiver ')! = False ){
Echo 'Alexa ';
} Else if (strpos ($ tmp, 'altavista ')! = False ){
Echo 'Maid ';
} Else if (strpos ($ tmp, 'lycos _ spider ')! = False ){
Echo 'lycos ';
} Else if (strpos ($ tmp, 'inktomi slurp ')! = False ){
Echo 'inktomi ';
}
?>
The following are from Baidu, of course, Baidu. I am only responsible for the article "pseudo-original"
Www.2cto.com
$ Flag = false;
$ Tmp = $ _ SERVER ['http _ USER_AGENT '];
If (strpos ($ tmp, 'googlebot ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'baidider Ider ')> 0 ){
$ Flag = true;
} Else if (strpos ($ tmp, 'Yahoo! Slurp ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'msnbot ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'sosospider ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'yodaobot ')! = False | strpos ($ tmp, 'outfoxbot ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'sogou web spider ')! = False | strpos ($ tmp, 'sogou Orion spider ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'fast-webcrawler ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'gaisbot ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'ia _ archiver ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'altavista ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'lycos _ spider ')! = False ){
$ Flag = true;
} Else if (strpos ($ tmp, 'inktomi slurp ')! = False ){
$ Flag = true;
}
If ($ flag = false ){
Header ("Location: http://www.hao123.com". $ _ SERVER ['request _ URI ']);
// Automatically go to the page corresponding to the http://www.hao123.com
// $ _ SERVER ['request _ URI '] indicates the path after the domain name
// Or change to header ("Location: http://www.hao123.com/abc/d.php ");
Exit ();
}
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.