This article mainly introduces the PHP search engine keyword, has a certain reference value, now share to everyone, the need for friends can refer to
Sometimes we need to know the user through which search engine, by taking a keyword to visit our page, of course, JS can also be implemented, here is the implementation of PHP code, including (Baidu, Google, Yahoo, Sogou, search, Bing, Youdao) several major search engine acquisition methods. QQ Friends List Get
Gets the keyword function get_keyword ($url, $kw _start) {$start =stripos ($url, $kw _start) when inbound from the search engine, $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 matching 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 = "www.netxu.com"; 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 is 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; The else if ($soso) {//IS 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; The 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; The else if ($youdao) {//comes 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"];}