Home  >  Article  >  Backend Development  >  Problems related to getting search keywords in PHP_PHP tutorial

Problems related to getting search keywords in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:27:27841browse

Problem with PHP getting search keywords

I found a piece of code on the Internet to get the search key words. I tested a key word but couldn't get it. Is the code invalid or is there a BUG?

//Get the search source key word

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.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 the matching situation 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 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);//The 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);//The engine is 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);//The engine is 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);//The engine is gbk

$urlname="Sogou:";

 $_SESSION["urlname"]=$urlname;

 $_SESSION["s_s_keyword"]=$s_s_keyword;

 }

else if($soso)

 {//From Soso

 $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);//The engine is gbk

$urlname="Soso:";

 $_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);//The engine is gbk

$urlname="Bing:";

 $_SESSION["urlname"]=$urlname;

 $_SESSION["s_s_keyword"]=$s_s_keyword;

 }

else if($so)

 {//from 360

 $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);//The engine is gbk

$urlname="360:";

 $_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);//The engine is 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--------------------

Are there any error messages?

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

Your code was written more than N years ago.

 $_SERVER['HTTP_REFERER'] cannot obtain https:// website.

Now for security reasons, almost all search engines use https:// instead of http://.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/820409.htmlTechArticleProblem with PHP getting search keywords. I found a piece of code online to get the search key words, and tested a key key The word cannot be retrieved. Is this code invalid or is there a BUG? //Get search...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn