Visited (); // call the statistical function (preferably on the public page)
// Access Volume Function visited (){ $ Now_time = time (); $ Referer_url = $ _ SERVER ['http _ referer']; // address of the page from $ From_spider = $ keywords = ''; If (! Empty ($ referer_url )){ If (strstr ($ referer_url, 'www .baidu.com ')){ $ Referer_url = explode ("&", $ referer_url ); Foreach ($ referer_url as $ val ){ If (strstr ($ val, 'wd = ')){ $ Keywords = explode ("wd =", $ val ); $ Keywords = $ keywords [1]; } } $ From_spider = 'Baidu '; $ Keywords = urldecode ($ keywords ); } Elseif (strstr ($ referer_url, 'www. google ')){ $ Referer_url = explode ("&", $ referer_url ); Foreach ($ referer_url as $ val ){ If (strstr ($ val, 'Q = ')){ $ Keywords = explode ("q =", $ val ); $ Keywords = $ keywords [1]; } } $ From_spider = 'Google '; $ Keywords = urldecode ($ keywords ); } } // Only Baidu and Google are judged. The other principles are the same. $ TheData = array ( 'Access _ time' => $ now_time, 'Access _ date' => date ("Y-m-d", $ now_time ), 'Access _ url' => $ _ SERVER ['request _ url'], 'Referer _ url' = >$ _ SERVER ['http _ referer'], 'Keyword' => $ keywords, 'IP _ address' => $ _ SERVER ['remote _ ADDR '], 'From _ spider '=> $ from_spider, ); $ SQL = "insert into stats (access_time, access_date, access_url, referer_url, keywords, ip_address, from_spider) values ('". $ theData ['Access _ time']. "','". $ theData ['Access _ date']. "','". $ theData ['Access _ url']. "','". $ theData ['referer _ url']. "','". $ theData ['keyword']. "','". $ theData ['IP _ address']. "','". $ theData ['from _ spider ']. "')"; Echo $ SQL; exit; mysql_query ($ SQL ); } |