Home Backend Development PHP Tutorial php获取从百度搜索进入网站的关键词的详细代码_PHP

php获取从百度搜索进入网站的关键词的详细代码_PHP

Jun 01, 2016 am 11:57 AM
Key words

分享一个php获取从百度搜索进入网站的关键词的代码,有需要的朋友可以参考一下:

代码:
复制代码 代码如下:
function search_word_from() {
$referer = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'';
if(strstr( $referer, 'baidu.com')){ //百度
preg_match( "|baidu.+wo?r?d=([^\\&]*)|is", $referer, $tmp );
$keyword = urldecode( $tmp[1] );
$from = 'baidu'; (PS:T不错的PHP Q扣峮:276167802,验证:csl)
}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'];
}
?>

以上是本文关于php 该如何获取从百度搜索进入网站的关键词的详细代码,希望本文对广大php开发者有所帮助,感谢阅读本文。

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain what the explorer.exe process is Explain what the explorer.exe process is Feb 18, 2024 pm 12:11 PM

Explain what the explorer.exe process is

How to adjust aperture on Xiaomi Mi 14 Ultra? How to adjust aperture on Xiaomi Mi 14 Ultra? Mar 19, 2024 am 09:01 AM

How to adjust aperture on Xiaomi Mi 14 Ultra?

What is the highest graphics card that r5 5600x can drive? The latest performance of using 5600X with RX6800XT What is the highest graphics card that r5 5600x can drive? The latest performance of using 5600X with RX6800XT Feb 25, 2024 am 10:34 AM

What is the highest graphics card that r5 5600x can drive? The latest performance of using 5600X with RX6800XT

How to set Chinese in Cheat Engine? How to set Chinese in ce modifier How to set Chinese in Cheat Engine? How to set Chinese in ce modifier Mar 18, 2024 pm 01:20 PM

How to set Chinese in Cheat Engine? How to set Chinese in ce modifier

Which has a greater impact on performance, memory frequency or timing? Which has a greater impact on performance, memory frequency or timing? Feb 19, 2024 am 08:58 AM

Which has a greater impact on performance, memory frequency or timing?

What does the 0x0000004e error mean? What does the 0x0000004e error mean? Feb 18, 2024 pm 01:54 PM

What does the 0x0000004e error mean?

DaVinci Resolve Studio now supports AV1 hardware encoding for AMD graphics cards DaVinci Resolve Studio now supports AV1 hardware encoding for AMD graphics cards Mar 06, 2024 pm 10:04 PM

DaVinci Resolve Studio now supports AV1 hardware encoding for AMD graphics cards

How to update Honor MagicOS 8.0 on Honor 90 GT? How to update Honor MagicOS 8.0 on Honor 90 GT? Mar 18, 2024 pm 06:46 PM

How to update Honor MagicOS 8.0 on Honor 90 GT?

See all articles