How to use PHP to obtain guest IP and region location information and browser and source page instance sharing

Source: Internet
Author: User
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 ']; } }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.