How to use PHP to obtain guest IP and region location information and browser and source page instance sharing
<?php//this is similar to obtaining visitor information//convenient statistics class visitorinfo{//Get guest IP public Function getip () {$ip =false; if (!empty ($_server["Http_client_ip")) {$ip = $_server["Http_client_ip"]; } if (!empty ($_server[' http_x_forwarded_for ')) {$ips = Explode (",", $_server[' http_x_forwarded_for ') ); if ($IP) {array_unshift ($ips, $ip); $ip = FALSE;} for ($i = 0; $i < count ($ips); $i + +) {if (!eregi ("^ (10│172.16│192.168).", $ips [$i])) { $ip = $ips [$i]; Break }}} return ($ip? $ip: $_server[' remote_addr '); }//Get city, network operator and other information according to IP public function Findcitybyip ($ip) {$data = file_get_contents (' Http://ip.taobao.com/ser Vice/getipinfo.php?ip= '. $ip); Return Json_decode ($data, $assoc =true); }//Get user Browser type public function Getbrowser () {$agent =$_server["http_user_agent"]; if (Strpos ($agent, ' MSIE ')!==fAlse | | Strpos ($agent, ' rv:11.0 '))//ie11 judgment return "ie"; else if (Strpos ($agent, ' Firefox ')!==false) return "Firefox"; else if (Strpos ($agent, ' Chrome ')!==false) return "Chrome"; else if (Strpos ($agent, ' opera ')!==false) return ' Opera '; else if ((Strpos ($agent, ' Chrome ') ==false) &&strpos ($agent, ' Safari ')!==false) return ' Safari '; else return ' unknown '; }//Get site Source Public Function GetFromPage () {return $_server[' http_referer ']; } }