<?php /** * 分析搜索引擎到来的关键字 * * * @author zhangjun * @charset utf-8 */ class searchTerms { public static $banUrl = array('qq.com','localhost'); //不解析的referer 有利于加快程序处理速度 public static $parseHost = array('baidu','google','360','soso'); //能解析的referer /** * 主方法 * @return boolean || array */ public static function keyword(){ if(!isset($_SERVER['HTTP_REFERER'])) return false; $referer = trim($_SERVER['HTTP_REFERER']); $refererArr = parse_url($referer); //判断refer是否来至不需要分析的地址。 if(self::inBanUrl($refererArr['host'])) return false; $hasParseFun = false; foreach(self::$parseHost as $host) { if(strpos ($refererArr['host'],$host) !== false) { $hasParseFun = true; break; } } if(!$hasParseFun) return false; $queryVars = array(); parse_str($refererArr['query'], $queryVars); //调用每个搜索引擎的单独处理方法 $method = 'parse'.ucfirst($host); return self::$method($queryVars); } /* 已取消使用正则的方式。 public static function buldPattern($rule) { $host = str_replace('.', '.', $rule['host']); $patterns = array(); foreach ($rule['key'] as $key) { $patterns[] = $host . '.+?'.$key.'='; } return "/(?:" . implode('|', $patterns).')([^&]*)/'; }*/ public static function inBanUrl($referer) { foreach(self::$banUrl as $url) { if(strpos($url, $referer) !== false) return true; } return false; } public static function parseBaidu($params) { $searchTerms = ''; if(isset($params['kw'])) { $searchTerms = $params['kw']; } else if(isset ($params['wd'])) { $searchTerms = $params['wd']; } else if(isset ($params['word'])) { $searchTerms = $params['word']; } return isset($params['ie']) && (strtolower($params['ie']) == 'utf-8') ? $searchTerms : iconv('gbk', 'utf-8', $searchTerms); } public static function parseGoogle($params) { $searchTerms = ''; if(isset($params['q'])) { $searchTerms = $params['q']; } return isset($params['ie']) && ($params['ie'] == "GB") ? iconv('gbk', 'utf-8', $searchTerms) : $params['q']; } public static function parse360($params) { $searchTerms = ''; if(isset($params['q'])) { $searchTerms = $params['q']; } return $searchTerms; } public static function parseSoso($params) { $searchTerms = ''; if(isset($params['w'])) { $searchTerms = $params['w']; } return iconv('gbk', 'utf-8', $searchTerms); } }

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

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools
