Home > Backend Development > PHP Tutorial > PHP method to obtain website keywords from search engines such as Baidu and Google, Google keywords_PHP tutorial

PHP method to obtain website keywords from search engines such as Baidu and Google, Google keywords_PHP tutorial

WBOY
Release: 2016-07-13 09:47:04
Original
1101 people have browsed it

php获取从百度、谷歌等搜索引擎进入网站关键词的方法,谷歌关键词

本文实例讲述了php获取从百度、谷歌等搜索引擎进入网站关键词的方法。分享给大家供大家参考。具体实现方法如下:

<&#63;php
function search_word_from() {
 $referer = isset($_SERVER['HTTP_REFERER'])&#63;$_SERVER['HTTP_REFERER']:'';
 if(strstr( $referer, 'baidu.com')){ //百度
  preg_match( "|baidu.+wo&#63;r&#63;d=([^\\&]*)|is", $referer, $tmp );
  $keyword = urldecode( $tmp[1] );
  $from = 'baidu';
 }elseif(strstr( $referer, 'google.com') or strstr( $referer, 'google.cn')){ //谷歌
  preg_match( "|google.+q=([^\\&]*)|is", $referer, $tmp );
  $keyword = urldecode( $tmp[1] );
  $from = 'google';
 }elseif(strstr( $referer, 'so.com')){ //360搜索
  preg_match( "|so.+q=([^\\&]*)|is", $referer, $tmp );
  $keyword = urldecode( $tmp[1] );
  $from = '360'; 
 }elseif(strstr( $referer, 'sogou.com')){ //搜狗
  preg_match( "|sogou.com.+query=([^\\&]*)|is", $referer, $tmp );
  $keyword = urldecode( $tmp[1] );
  $from = 'sogou'; 
 }elseif(strstr( $referer, 'soso.com')){ //搜搜
  preg_match( "|soso.com.+w=([^\\&]*)|is", $referer, $tmp );
  $keyword = urldecode( $tmp[1] );
  $from = 'soso';
 }else {
  $keyword ='';
  $from = '';
 }
 return array('keyword'=>$keyword,'from'=>$from);
}
//以下为测试
//在搜索引擎搜索个关键词,进入网站
$word = search_word_from();
if(!empty($word['keyword'])){
 echo '关键字:'.$word['keyword'].' 来自:'.$word['from'];
}
&#63;>

Copy after login

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1028967.htmlTechArticlephp获取从百度、谷歌等搜索引擎进入网站关键词的方法,谷歌关键词 本文实例讲述了php获取从百度、谷歌等搜索引擎进入网站关键词的方法...
Related labels:
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