PHP obtains client operating systems, browsers, languages, IP addresses, IP address locations, etc.
Class Client {// Obtain the function Get_Browser () {if (! Empty ($ _ SERVER ['http _ USER_AGENT ']) {$ br = $ _ SERVER ['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 = 'chromi';} elseif (preg_match ('/Safari/I', $ br )) {$ br = 'Safari ';} elseif (preg_match ('/Opera/I ', $ br) {$ br = 'Opera ';} else {$ br = 'other';} return $ br;} else {return "unknow ";}}/// Obtain the visitor's browser language function Get_Lang () {if (! Empty ($ _ SERVER ['http _ ACCEPT_LANGUAGE ']) {$ lang = $ _ SERVER ['http _ ACCEPT_LANGUAGE']; $ lang = substr ($ lang ); if (preg_match ("/zh-cn/I", $ lang) {$ lang = "simplified Chinese";} elseif (preg_match ("/zh/I ", $ lang) {$ lang = "traditional Chinese";} else {$ lang = "English";} return $ lang ;}else {return "unknow ";}} /// obtain the guest operating system function Get_ OS () {if (! Empty ($ _ SERVER ['http _ USER_AGENT ']) {$ 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;} else {return "unknow" ;}/// get Visitor real ipfunction 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 ("/^ (10 | 172 \. 16 | 192 \. (168 )\. /I ", $ ips [$ I]) {// exclude LAN ip address $ ip = $ ips [$ I]; break ;}} $ tip = empty ($ _ SERVER ['remote _ ADDR '])? $ Ip: $ _ SERVER ['remote _ ADDR ']; if ($ tip = "127.0.0.1") {// Obtain the local real IP return self: get_onlineip ();} else {return $ tip ;}/// obtain the local real IP function get_onlineip () {$ ip_json = @ file_get_contents (" http://ip.taobao.com/service/getIpInfo.php?ip= Myip "); $ ip_arr = json_decode (stripslashes ($ ip_json), 1); if ($ ip_arr ['code'] = 0) {return $ ip_arr ['data'] ['IP'] ;}/// obtain the location name of the visitor based on the ip address. function 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 taobao ip $ ip_arr = json_decode (stripslashes ($ ip_json), 1); if ($ ip_arr ['code'] = 0) {return $ ip_arr;} else {return false ;}}}