PHP函数获取搜索引擎来源和关键字
PHP方法获取哪个搜索引擎来源和关键字。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
<?php /** * 搜索引擎关键字和引擎来源 */ class get_engine { //得到内容 function get_e(){ if (empty($_SERVER['HTTP_REFERER'])) { return; } $url = $_SERVER['HTTP_REFERER']; $arr = $this->save_www_iiwnet_com_keyword($url,$url); $keywords = $arr['keywords']; $searchengine = $arr['searchengine']; $data = array( 'keywords' => $keywords, 'searchengine' => $searchengine, ); // $this->db->insert('engine',$data); return $data; } //根据主机来源 function save_www_iiwnet_com_keyword($domain,$path){ $keywords = ''; $searchengine = ''; if(strpos($domain, 'google.com.tw')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){ $searchengine = 'GOOGLE TAIWAN'; $keywords = urldecode($regs[1]); // google taiwan } if(strpos($domain,'google.cn')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){ $searchengine = 'GOOGLE CHINA'; $keywords = urldecode($regs[1]); // google china } if(strpos($domain,'google.com')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){ $searchengine = 'GOOGLE'; $keywords = urldecode($regs[1]); // google }else if(strpos($domain,'baidu.')!==false && preg_match('/wd=([^&]*)/i',$path,$regs)){ $searchengine = 'BAIDU'; $keywords = urldecode($regs[1]); // baidu }else if(strpos($domain,'baidu.')!==false && preg_match('/word=([^&]*)/i',$path,$regs)){ $searchengine = 'BAIDU'; $keywords = urldecode($regs[1]); // baidu }else if(strpos($domain,'114.vnet.cn')!== false && preg_match('/kw=([^&]*)/i',$path,$regs)){ $searchengine = 'CT114'; $keywords = urldecode($regs[1]); // ct114 }else if(strpos($domain,'iask.com')!==false && preg_match('/k=([^&]*)/i',$path,$regs)){ $searchengine = 'IASK'; $keywords = urldecode($regs[1]); // iask }else if(strpos($domain,'soso.com')!==false && preg_match('/w=([^&]*)/i',$path,$regs)){ $searchengine = 'SOSO'; $keywords = urldecode($regs[1]); // soso }else if(strpos($domain, 'sogou.com')!==false && preg_match('/query=([^&]*)/i',$path,$regs)){ $searchengine = 'SOGOU'; $keywords = urldecode($regs[1]); // sogou }else if(strpos($domain,'so.163.com')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){ $searchengine = 'NETEASE'; $keywords = urldecode($regs[1]); // netease }else if(strpos($domain,'yodao.com')!== false && preg_match('/q=([^&]*)/i',$path,$regs)){ $searchengine = 'YODAO'; $keywords = urldecode($regs[1]); // yodao }else if(strpos($domain,'zhongsou.com')!==false && preg_match('/word=([^&]*)/i',$path,$regs)){ $searchengine = 'ZHONGSOU'; $keywords = urldecode($regs[1]); // zhongsou }else if(strpos($domain,'search.tom.com')!==false && preg_match('/w=([^&]*)/i',$path,$regs)){ $searchengine = 'TOM'; $keywords = urldecode($regs[1]); // tom }else if(strpos($domain,'live.com')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){ $searchengine = 'MSLIVE'; $keywords = urldecode($regs[1]); // MSLIVE }else if(strpos($domain, 'tw.search.yahoo.com')!==false && preg_match('/p=([^&]*)/i',$path,$regs)){ $searchengine = 'YAHOO TAIWAN'; $keywords = urldecode($regs[1]); // yahoo taiwan }else if(strpos($domain,'cn.yahoo.')!==false && preg_match('/p=([^&]*)/i',$path,$regs)){ $searchengine = 'YAHOO CHINA'; $keywords = urldecode($regs[1]); // yahoo china }else if(strpos($domain,'yahoo.')!==false && preg_match('/p=([^&]*)/i',$path,$regs)){ $searchengine = 'YAHOO'; $keywords = urldecode($regs[1]); // yahoo }else if(strpos($domain,'msn.com.tw')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){ $searchengine = 'MSN TAIWAN'; $keywords = urldecode($regs[1]); // msn taiwan }else if(strpos($domain,'msn.com.cn')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){ $searchengine = 'MSN CHINA'; $keywords = urldecode($regs[1]); // msn china }else if(strpos($domain,'msn.com')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){ $searchengine = 'MSN'; $keywords = urldecode($regs[1]); // msn } if ($keywords == '') { $keywords = $path; } if ($searchengine == '') { $searchengine == $path; } return array('keywords'=>$keywords,'searchengine'=>$searchengine); } } $obj=new get_engine(); $arr=$obj->get_e(); var_dump($arr); ?> |
- codeigniter(ci)数据库操作教程简单增删改查
- JS判断手机号是否符合、手机验证码接收效果