Function get_user_browser () { If (empty ($ _ SERVER ['HTTP _ USER_AGENT ']) {// When the browser does not send the visitor's Information Return ''; } $ Agent = $ _ SERVER ['HTTP _ USER_AGENT ']; $ Browser = ''; $ Browser_ver = ''; If (preg_match ('/MSIEs ([^ s |;] +)/I', $ agent, $ regs )) { $ Browser = 'Internet Explorer '; // when MSIE is matched, the room that gets the number is in the array $ regs. $ Browser_ver = $ regs [1]; } Elseif (preg_match ('/FireFox/([^ s] +)/I', $ agent, $ regs )) { $ Browser = 'Firefox '; // when FireFox/is matched, obtain the digit that follows $ Browser_ver = $ regs [1]; } Elseif (preg_match ('/Maxthon/I', $ agent, $ regs )) { $ Browser = '(Internet Explorer'. $ browser_ver. ') Maxthon '; $ Browser_ver = ''; } Elseif (preg_match ('/Opera [s |/] ([^ s] +)/I', $ agent, $ regs )) { $ Browser = 'Opera '; $ Browser_ver = $ regs [1]; } Elseif (preg_match ('/OmniWeb/(v *) ([^ s |;] +)/I', $ agent, $ regs )) { $ Browser = 'omniweb '; $ Browser_ver = $ regs [2]; } Elseif (preg_match ('/Netscape ([d] *)/([^ s] +)/I', $ agent, $ regs )) { $ Browser = 'netscape '; $ Browser_ver = $ regs [2]; } Elseif (preg_match ('/safari/([^ s] +)/I', $ agent, $ regs )) { $ Browser = 'safari '; $ Browser_ver = $ regs [1]; } Elseif (preg_match ('/NetCaptors ([^ s |;] +)/I', $ agent, $ regs )) { $ Browser = '(Internet Explorer'. $ browser_ver. ') NetCaptor '; $ Browser_ver = $ regs [1]; } Elseif (preg_match ('/Lynx/([^ s] +)/I', $ agent, $ regs )) { $ Browser = 'lynx '; $ Browser_ver = $ regs [1]; } If (! Empty ($ browser )) { Return addslashes ($ browser. ''. $ browser_ver); // escape quotation marks } Else { Return 'unknow browser '; } } Determine if it is a spider
Function is_spider ($ record = true) // you can check whether the image is a spider. { Static $ spider = NULL; If ($ spider! = NULL) { Return $ spider ;// } If (empty ($ _ SERVER ['HTTP _ USER_AGENT ']) { $ Spider = ''; Return ''; } $ Searchengine_bot = array ( 'Googlebot ', 'Mediapartners-google ', 'Baidider ider + ', 'Msnbot ', 'Yodaobot ', 'Yahoo! Slurp ;', 'Yahoo! Slurp china ;', 'Askspider ', 'Sogou web spider ', 'Sogou push spider' ); $ Searchengine_name = array ( 'Google ', 'Google adsens ', 'Baidu ', 'Msn ', 'Yodao ', 'Yahoo ', 'Yahoo China ', 'Iask ', 'Sogou ', 'Sogou' ); $ Spider = strtolower ($ _ SERVER ['HTTP _ USER_AGENT ']); // convert the user's browser information to lowercase letters. Foreach ($ searchengine_bot AS $ key => $ value) { If (strpos ($ spider, $ value )! = False) // The value is definitely not equal to the value of 0. { $ Spider = $ searchengine_name [$ key]; // return the corresponding seo/seo.html "target =" _ blank "> Search Engine name Return $ spider; } } $ Spider = ''; Return ''; } |