PHP: Getting search keywords _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Questions about retrieving search keywords in PHP. PHP retrieval of search keywords I found a piece of code on the Internet to achieve retrieval of the search for the keyword, and I tested whether the code is invalid or there is a BUG there? Retrieving search keywords in PHP

I found a piece of code on the Internet to get the search token. I tested whether the code is invalid or there is a BUG?

// Retrieve the search source Guan jianzi

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 matching information 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"];

// Retrieve domain names without parameters

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

$ Burl = $ matches [1];

// Match 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 sousearch

$ 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 = "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); // 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 is N years ago.

$ _ SERVER ['http _ referer'] cannot obtain https: // websites.

For the sake of security, almost all search engines use https: // instead of http ://.

Token finds a piece of code on the Internet to obtain the search token. if a token cannot be obtained, is this code invalid or is there a BUG? // Search...

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.