// Obtain the keyword from the search engine inbound
- // 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 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 );
- $ S_s_keyword = "";
- $ Bul = $ _ SERVER ['http _ referer'];
- // Retrieve domain names without parameters
- 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); // 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 ($ 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;
- $ 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"];
- }
- ?>
-
(In the processing, remember to deal with the encoding problem, because of different search engines, returned results, some may be GBK, some may be the content of the UTF-8 format. Function 2. this is also good. you can try it. The code is as follows:
- // Obtain the keyword of the search engine entry
- $ _ 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, 'google. 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, '2017 .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 = 'deletease ';
- $ 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;
- }
- ?>
|