-
-
//取得搜尋引擎入站關鍵字
- //by bbs.it-home.org
- function get_keyword($url,$kw_start)
- {
- $start=stripos($url,$kw_start);
- $url=substr($url,$start+strlen($kw_start) );
- $start=stripos($url,'&');
- if ($start>0)
- {
- $start=stripos($url,'&');
- $s_s_keyword=substr($url,0,$start);
- }
- else
- {
- $s_s_keyword=substr($url,0);
- }
- return $ s_s_keyword;
- }
$url=isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'';//取得入站url。
- $search_1="google.com"; //q= utf8
- $search_2="baidu.com"; //wd= gbk
- $search_3="yahoo.cn"; //q= utf8
- $search_4="sogou.com"; //query= gbk
- $search_5="soso.com"; //w= gbk
- $search_6="bing.com"; //q = utf8
- $search_7="youdao.com"; //q= utf8
$google=preg_match("/b{$search_1}b/",$url);/ /記錄匹配情況,用於入站判斷。
- $baidu=preg_match("/b{$search_2}b/",$url);
- $yahoo=preg_match("/b{$search_3}b/",$url);
- $ sogou=preg_match("/b{$search_4}b/",$url);
- $soso=preg_match("/b{$search_5}b/",$url);
- $bing=preg_match( "/b{$search_6}b/",$url);
- $youdao=preg_match("/b{$search_7}b/",$url);
- $s_s_keyword="";
- $bul=$_SERVER['HTTP_REFERER'];
- //取得沒參數網域
- preg_match('@^(?:http://)?([^/]+)@i',$bul ,$matches);
- $burl=$matches[1];
- //匹配網域設定
- $curl="bbs.it-home.org";
- if($burl!= $curl){
- if ($google)
- {//來自google
- $s_s_keyword=get_keyword($url,'q=');//關鍵字前的字元為"q="。
- $s_s_keyword=urldecode($s_s_keyword);
- $urlname="Google:";
- $_SESSION["urlname"]=$urlname;
- $_SESSION["s_s_keyword"]=$s_s_keywordword ;
- //$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎為gbk
- }
- else if($baidu)
- {//來自百度
- $s_s_keyword=get_keyword($url,'wd=');//關鍵字前的字元為"wd="。
- $s_s_keyword=urldecode($s_s_keyword);
- $s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎為gbk
- $urlname="百度:";
- $_SESSION["urlname"]=$urlname;
- $_SESSION["s_s_keyword"]=$s_s_keyword;
- }
- else if($yahoo)
- {//來自雅虎
- $s_s_keyword=get_keyword($url,'q=');//關鍵字前的字元為"q="。
- $s_s_keyword=urldecode($s_s_keyword);
- //$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎為gbk
- $urlname="雅虎:雅虎:雅虎";
- $_SESSION["urlname"]=$urlname;
- $_SESSION["s_s_keyword"]=$s_s_keyword;
- }
- else if($sogou)
- {//來自搜狗
- $s_s_keyword=get_keyword($url,'query=');//關鍵字前的字元為"query="。
- $s_s_keyword=urldecode($s_s_keyword);
- $s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎為gbk
- $urlname="搜尋狗:";
- $_SESSION["urlname"]=$urlname;
- $_SESSION["s_s_keyword"]=$s_s_keyword;
- }
- else if($soso)
- {//來自搜尋
- $s_s_keyword=get_keyword($url,'w=');//關鍵字前的字元為"w="。
- $s_s_keyword=urldecode($s_s_keyword);
- $s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎為gbk
- $urlname="搜尋搜尋:" ;
- $_SESSION["urlname"]=$urlname;
- $_SESSION["s_s_keyword"]=$s_s_keyword;
- }
- else if($bing)
- {//來自必應
- $s_s_keyword=get_keyword($url,'q=');//關鍵字前的字元為"q="。
- $s_s_keyword=urldecode($s_s_keyword);
- //$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎為gbk
- $urlname=" :";
- $_SESSION["urlname"]=$urlname;
- $_SESSION["s_s_keyword"]=$s_s_keyword;
- }
- else if($youdao)
- {///🎜>{//來自有道
- $s_s_keyword=get_keyword($url,'q=');//關鍵字前的字元為"q="。
- $s_s_keyword=urldecode($s_s_keyword);
- //$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎為gbk
- $urlname="有道:";
- $_SESSION["urlname"]=$urlname;
- $_SESSION["s_s_keyword"]=$s_s_keyword;
- }
- else{
- $urlname=$burl; 🎜>$s_s_keyword="";
- $_SESSION["urlname"]=$urlname;
- $_SESSION["s_s_keyword"]=$s_s_keyword;
- }
- $s_urlname=$name; 🎜>$s_urlkey=$s_s_keyword;
- }
- else{
- $s_urlname=$_SESSION["urlname"];
- $s_urlkey=$_SESSION["s_s_key_key"]
- $s_urlkey=$_SESSION["s_s_key_key"]
- $s_urlkey=$_SESSION["s_s_key_key"]; 🎜>?>
-
-
-
- 複製程式碼
說明:在處理時,記得處理好編碼的問題,因為不同的搜尋引擎,回傳的結果,有的可能是GBK,有的則可能是UTF- 8格式的內容。
函數2,這個也不錯,大家可以試試看。
程式碼如下:
-
-
//取得搜尋引擎的入口關鍵字
- $_SERVER['HTTP_REFERER']='http://www .baidu.com/s?wd=http://bbs.it-home.org';
- echo save_www_iiwnet_com_keyword('http://www.baidu.com/s?wd=http://bbs.it -home.org','http://www.baidu.com/s?wd=http://bbs.it-home.org');
- function save_www_iiwnet_com_keyword($domain,$path){
- 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
- }elseif(strpos($domain,'baidu.') !==false && preg_match('/wd=([^&]*)/i',$path,$regs)){
- $searchengine = 'BAIDU';
- $keywords = urldecode($regs [1]); // baidu
- }elseif(strpos($domain,'baidu.')!==false && preg_match('/word=([^&]*)/i',$path,$ regs)){
- $searchengine = 'BAIDU';
- $keywords = urldecode($regs[1]); // baidu
- }elseif(strpos($domain,'114.vnet.cn' )!== false && preg_match('/kw=([^&]*)/i',$path,$regs)){
- $searchengine = 'CT114';
- $keywords = urldecode($ regs[1]); // ct114
- }elseif(strpos($domain,'iask.com')!==false && preg_match('/k=([^&]*)/i',$path ,$regs)){
- $searchengine = 'IASK';
- $keywords = urldecode($regs[1]); // iask
- }elseif(strpos($domain,'soso.com' )!==false && preg_match('/w=([^&]*)/i',$path,$regs)){
- $searchengine = 'SOSO';
- $keywords = urldecode($ regs[1]); // soso
- }elseif(strpos($domain, 'sogou.com')!==false && preg_match('/query=([^&]*)/i',$path ,$regs)){
- $searchengine = 'SOGOU';
- $keywords = urldecode($regs[1]); // sogou
- }elseif(strpos($domain,'so.163. com')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){
- $searchengine = 'NETEASE';
- $keywords = urldecode ($regs[1]); // netease
- }elseif(strpos($domain,'yodao.com')!== false && preg_match('/q=([^&]*)/i', $path,$regs)){
- $searchengine = 'YODAO';
- $keywords = urldecode($regs[1]); // yodao
- }elseif(strpos($domain,'zhongsou. com')!==false && preg_match('/word=([^&]*)/i',$path,$regs)){
- $searchengine = 'ZHONGSOU';
- $keywords = urldecode ($regs[1]); // zhongsou
- }elseif(strpos($domain,'search.tom.com')!==false && preg_match('/w=([^&]*)/i ',$path,$regs)){
- $searchengine = 'TOM';
- $keywords = urldecode($regs[1]); // tom
- }elseif(strpos($domain,' live.com')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){
- $searchengine = 'MSLIVE';
- $keywords = urldecode($regs[1]); // MSLIVE
- }elseif(strpos($domain, 'tw.search.yahoo.com')!==false && preg_match('/p=([^&] *)/i',$path,$regs)){
- $searchengine = 'YAHOO TAIWAN';
- $keywords = urldecode($regs[1]); // yahoo taiwan
- }elseif( strpos($domain,'cn.yahoo.')!==false && preg_match('/p=([^&]*)/i',$path,$regs)){
- $searchengine = 'YAHOO CHINA';
- $keywords = urldecode($regs[1]); // yahoo china
- }elseif(strpos($domain,'yahoo.')!==false && preg_match('/p=( [^&]*)/i',$path,$regs)){
- $searchengine = 'YAHOO';
- $keywords = urldecode($regs[1]); // yahoo
- } elseif(strpos($domain,'msn.com.tw')!==false && preg_match('/q=([^&]*)/i',$path,$regs)){
- $searchengine = 'MSN TAIWAN';
- $keywords = urldecode($regs[1]); // msn taiwan
- }elseif(strpos($domain,'msn.com.cn')!==false && preg_match ('/q=([^&]*)/i',$path,$regs)){
- $searchengine = 'MSN CHINA';
- $keywords = urldecode($regs[1]); // msn china
- }elseif(strpos($domain,'msn.com')!==false && preg_match('/q=([^&]*)/i',$path,$regs)) {
- $searchengine = 'MSN';
- $keywords = urldecode($regs[1]); // msn
- }
- return $keywords;
- }
- ?>
複製程式碼
|