PHP access to client operating systems, browsers, languages, IP,IP attribution, etc.

Source: Internet
Author: User
Tags count empty php class return client linux
<?php class Client {////Gets the Guest browser type function Get_browser () {if (!empty ($_server[' http_user_agent '])) {$BR = $_se
    		rver[' Http_user_agent '];
			if (Preg_match ('/msie/i ', $br)) {$br = ' msie ';
    		} elseif (Preg_match ('/firefox/i ', $br)) {$br = ' Firefox ';
       		} elseif (Preg_match ('/chrome/i ', $br)) {$br = ' Chrome ';
    		} elseif (Preg_match ('/safari/i ', $br)) {$br = ' Safari ';
    		} elseif (Preg_match ('/opera/i ', $br)) {$br = ' Opera ';
    		}else {$br = ' other ';
   		return $BR;
   		} else{return "Unknow"; ////Gets the Guest browser language function Get_lang () {if (!empty ($_server[' http_accept_language '))) {$lang = $_server[' Http_
   			 Accept_language '];
    		$lang = substr ($lang, 0,5);
    		if (Preg_match ("/zh-cn/i", $lang)) {$lang = "Simplified Chinese";
    		} elseif (Preg_match ("/zh/i", $lang)) {$lang = "Traditional Chinese";
    		} else{$lang = "中文版"; } return$lang;
   		} else{return "Unknow"; ////Get guest OS function Get_os () {if (!empty ($_server[' http_user_agent '))) {$OS = $_server[' Http_user_ag
      		ENT '];
    		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;
   		} else{return "Unknow"; ////Get visitors true Ip function get_ip_addr () {if (!empty ($_server["Http_client_ip")) {$ip = $_server
   		["Http_client_ip"];
   		} if (!empty ($_server[' http_x_forwarded_for ')) {//get proxy IP $ips = explode (', ', $_server[' http_x_forwarded_for ']); 
   		} if ($ip) {$ips = Array_unshift ($ips, $IP); } $counT = count ($ips); For ($i =0 $i < $count $i + +) {if (!preg_match ("/^ (10172\.16192\.168) \./i", $ips [$i])) {//excluding LAN IP $IP = $ips
	      		[$i];    
	      	Break }} $tip = Empty ($_server[' remote_addr '))? 
   		$ip: $_server[' remote_addr '];   
   		if ($tip = = "127.0.0.1") {//Get local real IP return Self::get_onlineip (); 
   		else{return $tip; ////get local real IP function Get_onlineip () {$ip _json = @file_get_contents ("Http://ip.taobao.com/service/getIpInf
		O.php?ip=myip ");
		$ip _arr=json_decode (stripslashes ($ip _json), 1);
		if ($ip _arr[' code ']==0) {return $ip _arr[' data '] [' IP '];    
		}////the visitor location based on Ip get_ip_from ($ip = ') {if (empty ($ip)) {$ip = Self::getip (); } $ip _json= @file_get_contents ("http://ip.taobao.com/service/getIpInfo.php?ip=". $ip)//According to the Taobao IP $ip _arr=json_d
   		Ecode (stripslashes ($ip _json), 1);
   		if ($ip _arr[' code ']==0) {return $ip _arr; else {return FAlse; }
   		
	} 

}


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.