Home > Backend Development > PHP Tutorial > PHP determines whether the visitor is a spider or an ordinary user_PHP Tutorial

PHP determines whether the visitor is a spider or an ordinary user_PHP Tutorial

WBOY
Release: 2016-07-13 17:47:45
Original
1022 people have browsed it

When I’m about to start doing regular SEO, I still use the black link code, but it’s a little bit special. Of course, I’ll test it myself first to see if it’s feasible.
You need to create a PHP document to record whether the visitor is a spider or an ordinary user. Specifically, it is judged based on PHP's $_SERVER['HTTP_USER_AGENT']
The specific code is as follows:

$tmp = $_SERVER['HTTP_USER_AGENT'];
if(strpos($tmp, 'Googlebot') !== false){
echo 'Google';
} else if(strpos($tmp, 'Baiduspider') >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 'soso';
} 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 'Gais';
} else if(strpos($tmp, 'ia_archiver') !== false){
echo 'Alexa';
} else if(strpos($tmp, 'altavista') !== false){
echo 'AltaVista';
} else if(strpos($tmp, 'lycos_spider') !== false){
echo 'Lycos';
} else if(strpos($tmp, 'Inktomi slurp') !== false){
echo 'Inktomi';
}
?>
The following is from Baidu, of course, the above is also from Baidu. I am only responsible for the "pseudo-original" articles

www.2cto.com

$flag = false;
$tmp = $_SERVER['HTTP_USER_AGENT'];
if(strpos($tmp, 'Googlebot') !== false){
$flag = true;
} else if(strpos($tmp, 'Baiduspider') >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 redirect to the corresponding webpage of http://www.hao123.com
// $_SERVER['REQUEST_URI'] is the path behind the domain name
// Or replace with header("Location: http://www.hao123.com/abc/d.php");
exit();
}
?>

Excerpted from http://www.xssxss.com/fuck/505.xss

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478470.htmlTechArticleI am going to start doing formal SEO. The black link code is still used, but it is a little special. Of course, test it yourself first Next, is it feasible? You need to create a PHP document to record whether the visitor is a spider or a general...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template