这篇文章主要介绍了php实现判断访问来路是否为搜索引擎机器人的方法,主要通过过滤$_SERVER[
本文实例讲述了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程序设计有所帮助。
,
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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

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

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
