PHP Get search keywords related issues

Source: Internet
Author: User
Tags curl


PHP Gets the search keyword problem



On the internet to find a piece of code to achieve search keyword, testing a key word can not be, is this code is invalid, or there is a bug?



Search Source keyword



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 inbound URL.



$search _1= "google.com.hk"; 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



$search _8= "so.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);



$so =preg_match ("/b{$search _8}b/", $url);



$s _s_keyword= "";



$bul =$_server[' Http_referer '];



$bul =$_request["Comelink"];



Get the domain name without parameters



Preg_match (' @^: http://)? ( [^/]+) @i ', $bul, $matches);



$burl = $matches [1];



Matching domain name settings



$curl = "www.hcyf07.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 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 ($SO)






$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






$_session["urlname"]= $urlname;



$_session["S_s_keyword"]= $s _s_keyword;



}



else if ($youdao)



{//Come 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;



$urlname = "Direct access";



$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"];



}



------Solution--------------------



Do you have any false hints?



------Solution--------------------



You so code is n years ago.



$_server[' Http_referer ' cannot get a https://Web site.



Now for security reasons, almost all search engines use https://rather than http://.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.