PHP Gets the operating system, IP, location, browser, ISP and other information _php class code

Source: Internet
Author: User
Tags php language

PHP language, browser, operating system, IP, geographical location, ISP, this PHP class has the following several methods, but also the usage description:

<?PHPclassclass_guest_info{functionGetlang () {$Lang=substr($_server[' Http_accept_language '], 0, 4); //use substr () to intercept a string, starting at 0 bits, and intercepting 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; }    functionGetbrowser () {$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; }    functionGetos () {$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; }    functionGetIP () {if(!emptyempty ($_server[' Http_client_ip '])) {        //If the variable is a non-null or nonzero value, empty () returns FALSE.             $IP=Explode(‘,‘,$_server[' Http_client_ip ']); }        ElseIf(!emptyempty ($_server[' Http_x_forwarded_for '])) {            $IP=Explode(‘,‘,$_server[' Http_x_forwarded_for ']); }        ElseIf(!emptyempty ($_server[' REMOTE_ADDR '])) {            $IP=Explode(‘,‘,$_server[' REMOTE_ADDR ']); }        Else {            $IP[0] = ' None '; }        return $IP[0]; }    Private functionGetaddisp () {$IP=$this-GetIP (); $ADDISP= Mb_convert_encoding (file_get_contents(' http://open.baidu.com/ipsearch/stn=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; }    functionGetadd () {$ADD=$this-Getaddisp (); return $ADD[0]; }    functionGetisp () {$ISP=$this-Getaddisp (); if($ISP[0]! = ' None ' &&isset($ISP[1])) {            $ISP=$ISP[1]; }        Else {            $ISP= ' None '; }        return $ISP; }}?>
$obj=NewClass_guest_info;$obj->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. 

PHP Gets the operating system, IP, location, browser, ISP and other information _php class code

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.