php实现判断访问来路是否为搜索引擎机器人的方法,来路搜索引擎
本文实例讲述了php实现判断访问来路是否为搜索引擎机器人的方法。分享给大家供大家参考。具体分析如下:
很多时候我们需要对网站访客来路进行识别,针对真实用户与搜索引擎作不同动作实现,那么首先就需要判断是否为搜索引擎。
php判断方法非常简单,通过过滤$_SERVER['HTTP_USER_AGENT'] 参数即可进行识别,以下是摘录某开源程序的相关源码:
private function getRobot() { if (empty($_SERVER['HTTP_USER_AGENT'])) { return false; } $searchEngineBot = array( 'googlebot'=>'google', 'mediapartners-google'=>'google', 'baiduspider'=>'baidu', 'msnbot'=>'msn', 'yodaobot'=>'yodao', 'youdaobot'=>'yodao', 'yahoo! slurp'=>'yahoo', 'yahoo! slurp china'=>'yahoo', 'iaskspider'=>'iask', 'sogou web spider'=>'sogou', 'sogou push spider'=>'sogou', 'sosospider'=>'soso', 'spider'=>'other', 'crawler'=>'other', ); $spider = strtolower($_SERVER['HTTP_USER_AGENT']); foreach ($searchEngineBot as $key => $value) { if (strpos($spider, $key)!== false) { return $value; } } return false; } public function isRobot() { if($this->getRobot()!==false) { return true; } return false; }
希望本文所述对大家的php程序设计有所帮助。
Statement
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks agoByDDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment