PHP gets client information class
Getlang (); Get the language of your visitors: Simplified Chinese, Traditional Chinese, 中文版. $obj->getbrowser (); Get the Guest browser: MSIE, Firefox, Chrome, Safari, Opera, other. $obj->getos (); Get guest OS: Windows, MAC, Linux, Unix, BSD, other. $obj->getip (); Gets the guest IP address. $obj->getadd (); Get the visitor's location and use Baidu to hide the interface. $obj->getisp (); Get the guest ISP and use Baidu to hide the interface. */class class_guest_info{function Getlang () {$Lang = substr ($_server[' http_accept_language '], 0, 4); Use SUBSTR () to intercept a string, starting with 0 bits, intercept 4 characters if (Preg_match ('/zh-c/i ', $Lang)) {//preg_match () regular expression matching function $Lang = ' Simplified Chinese '; } elseif (Preg_match ('/zh/i ', $Lang)) {$Lang = ' Traditional Chinese '; } else {$Lang = ' 中文版 '; } return $Lang; } function Getbrowser () {$Browser = $_server[' http_user_agent '); if (Preg_match ('/msie/i ', $Browser)) {$Browser = ' MSIE '; } elseif (Preg_match ('/firefox/i ', $Browser)) {$Browser = ' Firefox '; } elseif (Preg_match ('/chrome/i ', $Browser)) {$Browser = ' Chrome '; } elseif (Preg_match ('/safari/i ', $Browser)) {$Browser = ' Safari '; } elseif (Preg_match ('/opera/i ', $Browser)) {$Browser = ' Opera '; } else {$Browser = ' other '; } return $Browser; } function Getos () {$OS = $_server[' http_user_agent '); if (Preg_match ('/win/i ', $OS)) {$OS = ' Windows '; } elseif (Preg_match ('/mac/i ', $OS)) {$OS = ' mac '; } elseif (Preg_match ('/linux/i ', $OS)) {$OS = ' Linux '; } elseif (Preg_match ('/unix/i ', $OS)) {$OS = ' Unix '; } elseif (Preg_match ('/bsd/i ', $OS)) {$OS =' BSD '; } else {$OS = ' other '; } return $OS; } function GetIP () {if (!empty ($_server[' http_client_ip ')) {//If the variable is a non-null or nonzero value, empty () returns FALSE. $IP = Explode (', ', $_server[' http_client_ip '); } elseif (!empty ($_server[' http_x_forwarded_for ')) {$IP = explode (', ', $_server[' http_x_forwarded _for ']); } elseif (!empty ($_server[' remote_addr ')) {$IP = explode (', ', $_server[' remote_addr ')); } else {$IP [0] = ' None '; } return $IP [0]; } Private Function Getaddisp () {$IP = $this->getip (); $ADDISP = mb_convert_encoding (file_get_contents (' http://open.baidu.com/ipsearch/s?tn=ipjson&wd= '. $IP), ' UTF-8 ', ' GBK '); Mb_convert_encoding () converts the character encoding. if (Preg_match ('/noresult/i ', $AddIsp)) {$AddIsp = ' None '; } else {$Sta = Stripos ($ADDISP, $IP) + strlen ($IP) + strlen (' from '); $Len = Stripos ($AddIsp, ' "} ')-$Sta; $ADDISP = substr ($ADDISP, $Sta, $Len); } $ADDISP = Explode (' ', $ADDISP); return $ADDISP; } function Getadd () {$Add = $this->getaddisp (); return $ADD [0]; } function Getisp () {$Isp = $this->getaddisp (); if ($Isp [0]! = ' None ' && isset ($Isp [1])) {$Isp = $ISP [1]; } else {$Isp = ' None '; } return $ISP; }}?>
?