欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php获取从百度搜索进入网站的关键词_PHP教程

程序员文章站 2022-04-19 23:34:05
...

代码:

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'; www.jbxue.com
}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'];
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/675203.htmlTechArticle代码: function search_word_from() { $referer = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:''; if(strstr( $referer, 'baidu.com')){ //百度 preg_match( "|baidu.+wo...