Get inbound keywords from search engines
- 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 ']: ';//get the inbound 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);//record match for inbound judgment.
- $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 '];
- Get the no parameter domain name
- Preg_match (' @^ (?:/HTTP//)? ( [^/]+) @i ', $bul, $matches);
- $burl = $matches [1];
- Match Domain name settings
- $curl = "bbs.it-home.org";
- if ($burl! = $curl) {
- if ($google)
- {//From Google
- $s _s_keyword=get_keyword ($url, ' q= ');//The character before the keyword is "q=".
- $s _s_keyword=urldecode ($s _s_keyword);
- $urlname = "Google:";
- $_session["urlname"]= $urlname;
- $_session["S_s_keyword"]= $s _s_keyword;
- $s _s_keyword=iconv ("GBK", "UTF-8", $s _s_keyword);//engine for GBK
- }
- else if ($baidu)
- {//from Baidu
- $s _s_keyword=get_keyword ($url, ' wd= ');//The character before the keyword is "wd=".
- $s _s_keyword=urldecode ($s _s_keyword);
- $s _s_keyword=iconv ("GBK", "UTF-8", $s _s_keyword);//engine for GBK
- $urlname = "Baidu:";
- $_session["urlname"]= $urlname;
- $_session["S_s_keyword"]= $s _s_keyword;
- }
- else if ($yahoo)
- {//from Yahoo
- $s _s_keyword=get_keyword ($url, ' q= ');//The character before the keyword is "q=".
- $s _s_keyword=urldecode ($s _s_keyword);
- $s _s_keyword=iconv ("GBK", "UTF-8", $s _s_keyword);//engine for GBK
- $urlname = "Yahoo:";
- $_session["urlname"]= $urlname;
- $_session["S_s_keyword"]= $s _s_keyword;
- }
- else if ($sogou)
- {//from Sogou
- $s _s_keyword=get_keyword ($url, ' query= ');//The character before the keyword is "query=".
- $s _s_keyword=urldecode ($s _s_keyword);
- $s _s_keyword=iconv ("GBK", "UTF-8", $s _s_keyword);//engine for GBK
- $urlname = "Sogou:";
- $_session["urlname"]= $urlname;
- $_session["S_s_keyword"]= $s _s_keyword;
- }
- else if ($soso)
- {//From Search
- $s _s_keyword=get_keyword ($url, ' w= ');//The character before the keyword is "w=".
- $s _s_keyword=urldecode ($s _s_keyword);
- $s _s_keyword=iconv ("GBK", "UTF-8", $s _s_keyword);//engine for GBK
- $urlname = "Search:";
- $_session["urlname"]= $urlname;
- $_session["S_s_keyword"]= $s _s_keyword;
- }
- else if ($bing)
- {//From Bing
- $s _s_keyword=get_keyword ($url, ' q= ');//The character before the keyword is "q=".
- $s _s_keyword=urldecode ($s _s_keyword);
- $s _s_keyword=iconv ("GBK", "UTF-8", $s _s_keyword);//engine for GBK
- $urlname = "Bing:";
- $_session["urlname"]= $urlname;
- $_session["S_s_keyword"]= $s _s_keyword;
- }
- else if ($youdao)
- {//From Youdao
- $s _s_keyword=get_keyword ($url, ' q= ');//The character before the keyword is "q=".
- $s _s_keyword=urldecode ($s _s_keyword);
- $s _s_keyword=iconv ("GBK", "UTF-8", $s _s_keyword);//engine for GBK
- $urlname = "Youdao:";
- $_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= $urlname;
- $s _urlkey= $s _s_keyword;
- }
- else{
- $s _urlname=$_session["urlname"];
- $s _urlkey=$_session["S_s_keyword"];
- }
- ?>
Copy CodeNote: In processing, remember to handle the problem of coding, because the different search engines, the results returned, some may be gbk, some may be the content of the UTF-8 format. Function 2, this is also good, you can try. The code is as follows:
- Get portal keywords for search engines
- $_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, ' 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;
- }
- ?>
Copy Code |