腾讯云网站解决方案帮您轻松应对建站成本高/网络不稳等常见问题

php 该如何获取从百度搜索进入网站的关键词

0
回复
387
查看
[复制链接]

691

主题

705

帖子

3万

积分

董事

Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72Rank: 72

积分
31863
     紫钻仅向指定用户开放  
发表于 19-2-20 09:26:53 | 显示全部楼层 |阅读模式
分享一个php获取从百度搜索进入网站的关键词的代码,有需要的朋友可以参考一下:
( N* ~4 K+ P& V4 ~9 v, K9 b; v( S, t: M: D1 x
代码:
# w1 B& O  t8 ?* ~& j/ D5 l0 h+ E# I% \: H* e2 T& N! W
  1. <font size="3"><span microsoft="" yahei",="" simsun;"=""><?php</span>
    * A3 }) ]8 Q: z' e8 F
  2. * _6 x. M% x" y. B# Z; [
  3. <span microsoft="" yahei",="" simsun;"="">function search_word_from() {</span>6 E- i1 i: H7 e# p& y. E
  4. <span microsoft="" yahei",="" simsun;"="">    $referer = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'';</span>" g+ c( j0 Q, A- R3 f. R
  5. <span microsoft="" yahei",="" simsun;"="">    if(strstr( $referer, 'baidu.com')){ //百度</span>
    , ^$ f* t6 F3 x9 Y, ?
  6. <span microsoft="" yahei",="" simsun;"="">        preg_match( "|baidu.+wo?r?d=([^\\&]*)|is", $referer, $tmp );</span>
    ) w0 F. r- z" p; P$ f1 u0 p* k
  7. <span microsoft="" yahei",="" simsun;"="">        $keyword = urldecode( $tmp[1] );</span>
    . A% c9 q4 c/ M( [' c) \
  8. <span microsoft="" yahei",="" simsun;"="">        $from = 'baidu'; (PS:T不错的PHP Q扣峮:276167802,验证:csl)</span>( T& j4 A, }2 J' R
  9. <span microsoft="" yahei",="" simsun;"="">    }elseif(strstr( $referer, 'google.com') or strstr( $referer, 'google.cn')){ //谷歌</span>
    0 s8 j. C# P' e( I
  10. <span microsoft="" yahei",="" simsun;"="">        preg_match( "|google.+q=([^\\&]*)|is", $referer, $tmp );</span>3 Y/ v  b) \; j- }; {
  11. <span microsoft="" yahei",="" simsun;"="">        $keyword = urldecode( $tmp[1] );</span>% P9 g3 L) ]0 L0 D/ N/ G
  12. <span microsoft="" yahei",="" simsun;"="">        $from = 'google';</span>0 x+ k& g) |( @/ ~7 U( l, J" h
  13. <span microsoft="" yahei",="" simsun;"="">    }elseif(strstr( $referer, 'so.com')){ //360搜索</span>& y" T' Y6 Q8 X; ]0 x8 |5 w3 C
  14. <span microsoft="" yahei",="" simsun;"="">        preg_match( "|so.+q=([^\\&]*)|is", $referer, $tmp );</span>
    ( n- B, w& Q3 ?) J
  15. <span microsoft="" yahei",="" simsun;"="">        $keyword = urldecode( $tmp[1] );</span>, ?& k- L4 X- ~. `- B
  16. <span microsoft="" yahei",="" simsun;"="">        $from = '360';</span>! L( I. _  N8 `
  17. <span microsoft="" yahei",="" simsun;"="">    }elseif(strstr( $referer, 'sogou.com')){ //搜狗</span>* t5 ?/ i9 \" Z' `6 i5 n6 J
  18. <span microsoft="" yahei",="" simsun;"="">        preg_match( "|sogou.com.+query=([^\\&]*)|is", $referer, $tmp );</span>
    6 f2 G& Q2 p- X! d4 b
  19. <span microsoft="" yahei",="" simsun;"="">        $keyword = urldecode( $tmp[1] );</span>
    ! f3 n2 b4 q- f* R; s6 V5 U; q1 m
  20. <span microsoft="" yahei",="" simsun;"="">        $from = 'sogou'; </span>
    # k- W! g$ \0 ^4 c& G/ x+ t6 ~
  21. <span microsoft="" yahei",="" simsun;"="">    }elseif(strstr( $referer, 'soso.com')){ //搜搜</span>3 P" e6 I) n" b  p6 y
  22. <span microsoft="" yahei",="" simsun;"="">        preg_match( "|soso.com.+w=([^\\&]*)|is", $referer, $tmp );</span>8 g  G6 e5 U  N2 {$ \1 \8 j
  23. <span microsoft="" yahei",="" simsun;"="">        $keyword = urldecode( $tmp[1] );</span>5 w* c: k: v1 C* }' ~. |
  24. <span microsoft="" yahei",="" simsun;"="">        $from = 'soso';</span>
    : p! [7 ?; R, v. a
  25. <span microsoft="" yahei",="" simsun;"="">    }else {</span>8 B! b8 W! {5 l- r* r
  26. <span microsoft="" yahei",="" simsun;"="">        $keyword ='';</span>3 ?/ k, \1 A+ V0 |' ?
  27. <span microsoft="" yahei",="" simsun;"="">        $from = '';</span>
    ) @* i& U; I) L+ Y
  28. <span microsoft="" yahei",="" simsun;"="">    }</span>
    , A. Y5 J1 a" W- G" v3 u
  29. & O" z( o& E' |! ?4 ~) q
  30. <span microsoft="" yahei",="" simsun;"="">    return array('keyword'=>$keyword,'from'=>$from);</span>
    , C& e+ J$ ?3 k3 \
  31. <span microsoft="" yahei",="" simsun;"="">}</span>
    + a: r1 E! _* W

  32. 0 M* @# c: M" I! q7 K! H
  33. <span microsoft="" yahei",="" simsun;"="">//以下为测试</span>
    ) y" n. b7 P7 i, V; p3 r/ [. k
  34. <span microsoft="" yahei",="" simsun;"="">//在搜索引擎搜索个关键词,进入网站</span>6 {) J5 p2 d8 y  `+ X: {: w. `! g5 n
  35. <span microsoft="" yahei",="" simsun;"="">$word = search_word_from();</span>
    3 ~' j, r; N1 U7 o  `
  36. <span microsoft="" yahei",="" simsun;"="">if(!empty($word['keyword'])){</span>9 r! u; S) T: a5 _
  37. <span microsoft="" yahei",="" simsun;"="">    echo '关键字:'.$word['keyword'].' 来自:'.$word['from'];</span>
    3 o3 {! k  F: w' @! d6 i
  38. <span microsoft="" yahei",="" simsun;"="">}</span>
    7 U; X3 f9 l2 m0 p2 Y
  39. <span microsoft="" yahei",="" simsun;"="">?></span></font>
复制代码

+ Q+ ]9 a- Y7 E以上是本文关于php 该如何获取从百度搜索进入网站的关键词的详细代码
! E) W0 o3 U: ?, J) S

qiuqiufa.com

网站简介

球球发,是一家 Discuz! 商业插件、风格模板、网站源码、 Discuz!运营维护技术等于一体的交流分享网站,全站95%的资源都是免费下载,对于资源我们是每天更新,每个亲测资源最新最全---球球发(如果我们有侵犯了您权益的资源请联系我们删除