https://github.com/sinergi/php-browser-detector

Device.php:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="author" content="geovindu" />
<title>php 学习测试客户端环境</title>
<meta name="keywords" content="geovindu">
<meta name="description" content="涂聚文">
<meta
</head>
<body>
<?php
// win10 环境下用各浏览器检测的数据:
//谷歌Chrome Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36
//微软Edge Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134
//微软IE Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
//火狐Firefox Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0
//欧朋Opera Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.170 Safari/537.36 OPR/53.0.2907.68
//苹果Safari Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2 include('user_agent.php');
$geovindu="hi,how are you";
$number=2000;
$html="<br/>";
$word=$html.$geovindu.$number;
echo "geovindu<br/>";
echo "涂聚文";
echo($word);
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$lug=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
$ua = new CI_User_agent($user_agent);
$Duip=$_SERVER['SERVER_ADDR'];
$geovindu=new RemoteAddress(); //获取浏览器
function getBrowse()
{
global $_SERVER;
$Agent = $_SERVER['HTTP_USER_AGENT'];
$browseinfo='';
if(ereg('Mozilla', $Agent) && !ereg('MSIE', $Agent)){
$browseinfo = 'Netscape Navigator';
}
if(ereg('Opera', $Agent)) {
$browseinfo = 'Opera';
}
if(ereg('Mozilla', $Agent) && ereg('MSIE', $Agent)){ $browseinfo = 'Internet Explorer';
}
if(ereg('Chrome', $Agent)){
$browseinfo="Chrome";
}
if(ereg('Safari', $Agent)){
$browseinfo="Safari";
}
if(ereg('Firefox', $Agent)){
$browseinfo="Firefox";
} return $browseinfo;
}
//获取ip
function getIP()
{
global $_SERVER;
/* //方法1
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
} else if (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} else if (getenv('REMOTE_ADDR')) {
$ip = getenv('REMOTE_ADDR');
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}*/
//方法2
/*
error_reporting (E_ERROR | E_WARNING | E_PARSE);
if($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]){
$ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
}
elseif($HTTP_SERVER_VARS["HTTP_CLIENT_IP"]){
$ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
}
elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"]){
$ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
}
elseif (getenv("HTTP_X_FORWARDED_FOR")){
$ip = getenv("HTTP_X_FORWARDED_FOR");
}
elseif (getenv("HTTP_CLIENT_IP")){
$ip = getenv("HTTP_CLIENT_IP");
}
elseif (getenv("REMOTE_ADDR")){
$ip = getenv("REMOTE_ADDR");
}
else{
$ip = "Unknown";
}
*/
//$ip = $_SERVER["REMOTE_ADDR"];
//方法
/*
$ip = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
$ip = ($ip) ? $ip : $_SERVER["REMOTE_ADDR"];
*/ //方法
/*
foreach (array('HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR') as $key){
if (array_key_exists($key, $_SERVER) === true){
foreach (explode(',', $_SERVER[$key]) as $ip){
$ip = trim($ip); // Just to be safe if (filter_var($ip,
FILTER_VALIDATE_IP,
FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)
!== false) { //return $ip;
}
}
}
}
if(empty($ip))
{
$ip='127.0.0.1';
}
if($ip='::1')
{
$ip='127.0.0.1';
}
*/
/*
if ($_SERVER['HTTP_CLIENT_IP'] != '::1')
$ip = $_SERVER['HTTP_CLIENT_IP'];
else if ($_SERVER['HTTP_X_FORWARDED_FOR'] != '::1')
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if ($_SERVER['HTTP_X_FORWARDED'] != '::1')
$ip = $_SERVER['HTTP_X_FORWARDED'];
else if ($_SERVER['HTTP_FORWARDED_FOR'] != '::1')
$ip = $_SERVER['HTTP_FORWARDED_FOR'];
else if ($_SERVER['HTTP_FORWARDED'] != '::1')
$ip = $_SERVER['HTTP_FORWARDED'];
else if ($_SERVER['REMOTE_ADDR'] != '::1')
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = '127.0.0.1';
*/
// check for shared internet/ISP IP
if (!empty($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
} // check for IPs passing through proxies
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// check if multiple ips exist in var
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
$iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
foreach ($iplist as $ip) {
if (validate_ip($ip))
return $ip;
}
} else {
if (validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']))
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
}
if (!empty($_SERVER['HTTP_X_FORWARDED']) && validate_ip($_SERVER['HTTP_X_FORWARDED']))
return $_SERVER['HTTP_X_FORWARDED'];
if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && validate_ip($_SERVER['HTTP_FORWARDED_FOR']))
return $_SERVER['HTTP_FORWARDED_FOR'];
if (!empty($_SERVER['HTTP_FORWARDED']) && validate_ip($_SERVER['HTTP_FORWARDED']))
return $_SERVER['HTTP_FORWARDED'];
$ip=$_SERVER['REMOTE_ADDR'];
$ip="::1"?"127.0.0.1":$ip;
return $ip;
}
//获取用户系统
function getOS()
{
global $_SERVER;
$agent = $_SERVER['HTTP_USER_AGENT'];
$os = false;
if (eregi('win', $agent) && strpos($agent, '95')){
$os = 'Windows 95';
}elseif (eregi('win 9x', $agent) && strpos($agent, '4.90')){
$os = 'Windows ME';
}elseif (eregi('win', $agent) && ereg('98', $agent)){
$os = 'Windows 98';
}elseif (eregi('win', $agent) && eregi('nt 5.1', $agent)){
$os = 'Windows XP';
}elseif (eregi('win', $agent) && eregi('nt 5.2', $agent)){
$os = 'Windows 2003';
}elseif (eregi('win', $agent) && eregi('nt 5', $agent)){
$os = 'Windows 2000';
}elseif (eregi('win', $agent) && eregi('nt', $agent)){
$os = 'Windows NT';
}elseif (eregi('win', $agent) && ereg('32', $agent)){
$os = 'Windows 32';
}elseif (eregi('linux', $agent)){
$os = 'Linux';
}elseif (eregi('unix', $agent)){
$os = 'Unix';
}elseif (eregi('sun', $agent) && eregi('os', $agent)){
$os = 'SunOS';
}elseif (eregi('ibm', $agent) && eregi('os', $agent)){
$os = 'IBM OS/2';
}elseif (eregi('Mac', $agent) && eregi('PC', $agent)){
$os = 'Macintosh';
}elseif (eregi('PowerPC', $agent)){
$os = 'PowerPC';
}elseif (eregi('AIX', $agent)){
$os = 'AIX';
}elseif (eregi('HPUX', $agent)){
$os = 'HPUX';
}elseif (eregi('NetBSD', $agent)){
$os = 'NetBSD';
}elseif (eregi('BSD', $agent)){
$os = 'BSD';
}elseif (ereg('OSF1', $agent)){
$os = 'OSF1';
}elseif (ereg('IRIX', $agent)){
$os = 'IRIX';
}elseif (eregi('FreeBSD', $agent)){
$os = 'FreeBSD';
}elseif (eregi('teleport', $agent)){
$os = 'teleport';
}elseif (eregi('flashget', $agent)){
$os = 'flashget';
}elseif (eregi('webzip', $agent)){
$os = 'webzip';
}elseif (eregi('offline', $agent)){
$os = 'offline';
}else{
$os = 'Unknown';
}
return $os;
}
phpinfo(); //检测PHP环境
?>
操作系统:<input type="text" value="<?php echo $ua->platform() ?>" id="textos"/><br/>
浏览器: <input type="text" value="<?php echo $ua->browser() ?>" id="textbrowser"/><br/>
浏览器版本 <input type="text" value="<?php echo $ua->version() ?>" id="textversion"/><br/>
<input type="text" value="<?php echo $ua->robot() ?>" id="textrobot"/><br/>
手机品牌:<input type="text" value="<?php echo $ua->mobile() ?>" id="textmobile"/><br/>
客户环境检测:<input type="text" value="<?php echo $user_agent ?>" id="textgetusert" size="100"/><br/>
浏览器语言:<input type="text" value="<?php echo $lug ?>" id="textlg"/><br/>
<input type="text" value="<?php echo getIP() ?>" id="textip"/><br/>
<?php echo $Duip."<br/>" ?>
<?php echo $geovindu->getIpAddress() ?> </body>
</html>

  

user_agent.php:

<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/ // ------------------------------------------------------------------------ /**
* User Agent Class
*
* Identifies the platform, browser, robot, or mobile devise of the browsing agent
*
* @package CodeIgniter
* @subpackage Libraries
* @category User Agent
* @author ExpressionEngine Dev Team
* @link http://codeigniter.com/user_guide/libraries/user_agent.html
参考: https://en.wikipedia.org/wiki/Windows_NT geovindu 涂聚文 edit update 20180712
*/
class CI_User_agent { var $platforms = array (
'windows nt 10.0' => 'Win10',
'windows nt 6.3' => 'Windows 8.1 Windows Server 2012 R2',
'windows nt 6.2' => 'Win8',
'windows nt 6.1' => 'Win7',
'windows nt 6.0' => 'Win Longhorn',
'windows nt 5.2' => 'Win2003',
'windows nt 5.0' => 'Win2000',
'windows nt 5.1' => 'WinXP',
'windows nt 4.0' => 'Windows NT 4.0',
'winnt4.0' => 'Windows NT 4.0',
'winnt 4.0' => 'Windows NT',
'winnt' => 'Windows NT',
'windows 98' => 'Win98',
'win98' => 'Win98',
'windows 95' => 'Win95',
'win95' => 'Win95',
'windows' => 'Unknown Windows OS',
'os x' => 'MacOS X',
'ppc mac' => 'Power PC Mac',
'freebsd' => 'FreeBSD',
'ppc' => 'Macintosh',
'linux' => 'Linux',
'debian' => 'Debian',
'sunos' => 'Sun Solaris',
'beos' => 'BeOS',
'apachebench' => 'ApacheBench',
'aix' => 'AIX',
'irix' => 'Irix',
'osf' => 'DEC OSF',
'hp-ux' => 'HP-UX',
'netbsd' => 'NetBSD',
'bsdi' => 'BSDi',
'openbsd' => 'OpenBSD',
'gnu' => 'GNU/Linux',
'unix' => 'Unknown Unix OS'
); // The order of this array should NOT be changed. Many browsers return
// multiple browser types so we want to identify the sub-type first.
var $browsers = array(
'Flock' => 'Flock',
'Chrome' => 'Chrome',
'Opera' => 'Opera',
'MSIE' => 'IE',
'Internet Explorer' => 'IE',
'Shiira' => 'Shiira',
'Firefox' => 'Firefox',
'Chimera' => 'Chimera',
'Phoenix' => 'Phoenix',
'Firebird' => 'Firebird',
'Camino' => 'Camino',
'Netscape' => 'Netscape',
'OmniWeb' => 'OmniWeb',
'Safari' => 'Safari',
'Mozilla' => 'Mozilla',
'Konqueror' => 'Konqueror',
'icab' => 'iCab',
'Lynx' => 'Lynx',
'Links' => 'Links',
'hotjava' => 'HotJava',
'amaya' => 'Amaya',
'IBrowse' => 'IBrowse'
); var $mobiles = array(
// legacy array, old values commented out
'mobileexplorer' => 'Mobile Explorer',
// 'openwave' => 'Open Wave',
// 'opera mini' => 'Opera Mini',
// 'operamini' => 'Opera Mini',
// 'elaine' => 'Palm',
'palmsource' => 'Palm',
// 'digital paths' => 'Palm',
// 'avantgo' => 'Avantgo',
// 'xiino' => 'Xiino',
'palmscape' => 'Palmscape',
// 'nokia' => 'Nokia',
// 'ericsson' => 'Ericsson',
// 'blackberry' => 'BlackBerry',
// 'motorola' => 'Motorola' // Phones and Manufacturers
'motorola' => "Motorola",
'nokia' => "Nokia",
'palm' => "Palm",
'iphone' => "Apple iPhone",
'ipad' => "iPad",
'ipod' => "Apple iPod Touch",
'sony' => "Sony Ericsson",
'ericsson' => "Sony Ericsson",
'blackberry' => "BlackBerry",
'cocoon' => "O2 Cocoon",
'blazer' => "Treo",
'lg' => "LG",
'amoi' => "Amoi",
'xda' => "XDA",
'mda' => "MDA",
'vario' => "Vario",
'htc' => "HTC",
'samsung' => "Samsung",
'sharp' => "Sharp",
'sie-' => "Siemens",
'alcatel' => "Alcatel",
'benq' => "BenQ",
'ipaq' => "HP iPaq",
'mot-' => "Motorola",
'playstation portable' => "PlayStation Portable",
'hiptop' => "Danger Hiptop",
'nec-' => "NEC",
'panasonic' => "Panasonic",
'philips' => "Philips",
'sagem' => "Sagem",
'sanyo' => "Sanyo",
'spv' => "SPV",
'zte' => "ZTE",
'sendo' => "Sendo",
'huawei' => "Huawei",
'vivo' => "Vivo",
'oppo' => "OPPO",
// Operating Systems
'symbian' => "Symbian",
'SymbianOS' => "SymbianOS",
'elaine' => "Palm",
'palm' => "Palm",
'series60' => "Symbian S60",
'windows ce' => "Windows CE", // Browsers
'obigo' => "Obigo",
'netfront' => "Netfront Browser",
'openwave' => "Openwave Browser",
'mobilexplorer' => "Mobile Explorer",
'operamini' => "Opera Mini",
'opera mini' => "Opera Mini", // Other
'digital paths' => "Digital Paths",
'avantgo' => "AvantGo",
'xiino' => "Xiino",
'novarra' => "Novarra Transcoder",
'vodafone' => "Vodafone",
'docomo' => "NTT DoCoMo",
'o2' => "O2", // Fallback
'mobile' => "Generic Mobile",
'wireless' => "Generic Mobile",
'j2me' => "Generic Mobile",
'midp' => "Generic Mobile",
'cldc' => "Generic Mobile",
'up.link' => "Generic Mobile",
'up.browser' => "Generic Mobile",
'smartphone' => "Generic Mobile",
'cellphone' => "Generic Mobile"
); // There are hundreds of bots but these are the most common.
var $robots = array(
'googlebot' => 'Googlebot',
'msnbot' => 'MSNBot',
'slurp' => 'Inktomi Slurp',
'yahoo' => 'Yahoo',
'askjeeves' => 'AskJeeves',
'fastcrawler' => 'FastCrawler',
'infoseek' => 'InfoSeek Robot 1.0',
'lycos' => 'Lycos'
); var $agent = NULL; var $is_browser = FALSE;
var $is_robot = FALSE;
var $is_mobile = FALSE; var $languages = array();
var $charsets = array(); var $platform = '';
var $browser = '';
var $version = '';
var $mobile = '';
var $robot = ''; /**
* Constructor
*
* Sets the User Agent and runs the compilation routine
*
* @access public
* @return void
*/
public function __construct($agent = '')
{
if ($agent != '')
{
$this->agent = $agent;
}
else if (isset($_SERVER['HTTP_USER_AGENT']))
{
$this->agent = trim($_SERVER['HTTP_USER_AGENT']);
} if ( ! is_null($this->agent))
{
$this->_compile_data();
} //log_message('debug', "User Agent Class Initialized");
} // -------------------------------------------------------------------- /**
* Compile the User Agent Data
*
* @access private
* @return bool
*/
private function _compile_data()
{
$this->_set_platform(); foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function)
{
if ($this->$function() === TRUE)
{
break;
}
}
} // -------------------------------------------------------------------- /**
* Set the Platform
*
* @access private
* @return mixed
*/
private function _set_platform()
{
if (is_array($this->platforms) AND count($this->platforms) > 0)
{
foreach ($this->platforms as $key => $val)
{
if (preg_match("|".preg_quote($key)."|i", $this->agent))
{
$this->platform = $val;
return TRUE;
}
}
}
$this->platform = 'Unknown Platform';
} // -------------------------------------------------------------------- /**
* Set the Browser
*
* @access private
* @return bool
*/
private function _set_browser()
{
if (is_array($this->browsers) AND count($this->browsers) > 0)
{
foreach ($this->browsers as $key => $val)
{
if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match))
{
$this->is_browser = TRUE;
$this->version = $match[1];
$this->browser = $val;
$this->_set_mobile();
return TRUE;
}
}
}
return FALSE;
} // -------------------------------------------------------------------- /**
* Set the Robot
*
* @access private
* @return bool
*/
private function _set_robot()
{
if (is_array($this->robots) AND count($this->robots) > 0)
{
foreach ($this->robots as $key => $val)
{
if (preg_match("|".preg_quote($key)."|i", $this->agent))
{
$this->is_robot = TRUE;
$this->robot = $val;
return TRUE;
}
}
}
return FALSE;
} // -------------------------------------------------------------------- /**
* Set the Mobile Device
*
* @access private
* @return bool
*/
private function _set_mobile()
{
if (is_array($this->mobiles) AND count($this->mobiles) > 0)
{
foreach ($this->mobiles as $key => $val)
{
if (FALSE !== (strpos(strtolower($this->agent), $key)))
{
$this->is_mobile = TRUE;
$this->mobile = $val;
return TRUE;
}
}
}
return FALSE;
} // -------------------------------------------------------------------- /**
* Set the accepted languages
*
* @access private
* @return void
*/
private function _set_languages()
{
if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '')
{
$languages = preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))); $this->languages = explode(',', $languages);
} if (count($this->languages) == 0)
{
$this->languages = array('Undefined');
}
} // -------------------------------------------------------------------- /**
* Set the accepted character sets
*
* @access private
* @return void
*/
private function _set_charsets()
{
if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '')
{
$charsets = preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))); $this->charsets = explode(',', $charsets);
} if (count($this->charsets) == 0)
{
$this->charsets = array('Undefined');
}
} // -------------------------------------------------------------------- /**
* Is Browser
*
* @access public
* @return bool
*/
public function is_browser($key = NULL)
{
if ( ! $this->is_browser)
{
return FALSE;
} // No need to be specific, it's a browser
if ($key === NULL)
{
return TRUE;
} // Check for a specific browser
return array_key_exists($key, $this->browsers) AND $this->browser === $this->browsers[$key];
} // -------------------------------------------------------------------- /**
* Is Robot
*
* @access public
* @return bool
*/
public function is_robot($key = NULL)
{
if ( ! $this->is_robot)
{
return FALSE;
} // No need to be specific, it's a robot
if ($key === NULL)
{
return TRUE;
} // Check for a specific robot
return array_key_exists($key, $this->robots) AND $this->robot === $this->robots[$key];
} // -------------------------------------------------------------------- /**
* Is Mobile
*
* @access public
* @return bool
*/
public function is_mobile($key = NULL)
{
if ( ! $this->is_mobile)
{
return FALSE;
} // No need to be specific, it's a mobile
if ($key === NULL)
{
return TRUE;
} // Check for a specific robot
return array_key_exists($key, $this->mobiles) AND $this->mobile === $this->mobiles[$key];
} // -------------------------------------------------------------------- /**
* Is this a referral from another site?
*
* @access public
* @return bool
*/
public function is_referral()
{
if ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '')
{
return FALSE;
}
return TRUE;
} // -------------------------------------------------------------------- /**
* Agent String
*
* @access public
* @return string
*/
public function agent_string()
{
return $this->agent;
} // -------------------------------------------------------------------- /**
* Get Platform
*
* @access public
* @return string
*/
public function platform()
{
return $this->platform;
} // -------------------------------------------------------------------- /**
* Get Browser Name
*
* @access public
* @return string
*/
public function browser()
{
return $this->browser;
} // -------------------------------------------------------------------- /**
* Get the Browser Version
*
* @access public
* @return string
*/
public function version()
{
return $this->version;
} // -------------------------------------------------------------------- /**
* Get The Robot Name
*
* @access public
* @return string
*/
public function robot()
{
return $this->robot;
}
// -------------------------------------------------------------------- /**
* Get the Mobile Device
*
* @access public
* @return string
*/
public function mobile()
{
return $this->mobile;
} // -------------------------------------------------------------------- /**
* Get the referrer
*
* @access public
* @return bool
*/
public function referrer()
{
return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']);
} // -------------------------------------------------------------------- /**
* Get the accepted languages
*
* @access public
* @return array
*/
public function languages()
{
if (count($this->languages) == 0)
{
$this->_set_languages();
} return $this->languages;
} // -------------------------------------------------------------------- /**
* Get the accepted Character Sets
*
* @access public
* @return array
*/
public function charsets()
{
if (count($this->charsets) == 0)
{
$this->_set_charsets();
} return $this->charsets;
} // -------------------------------------------------------------------- /**
* Test for a particular language
*
* @access public
* @return bool
*/
public function accept_lang($lang = 'en')
{
return (in_array(strtolower($lang), $this->languages(), TRUE));
} // -------------------------------------------------------------------- /**
* Test for a particular character set
*
* @access public
* @return bool
*/
public function accept_charset($charset = 'utf-8')
{
return (in_array(strtolower($charset), $this->charsets(), TRUE));
} } // 获取IP
//https://raw.githubusercontent.com/zendframework/zend-http/master/src/PhpEnvironment/RemoteAddress.php
//http://php.net/manual/en/reserved.variables.server.php /**
* Functionality for determining client IP address.
*/
class RemoteAddress
{
/**
* Whether to use proxy addresses or not.
*
* As default this setting is disabled - IP address is mostly needed to increase
* security. HTTP_* are not reliable since can easily be spoofed. It can be enabled
* just for more flexibility, but if user uses proxy to connect to trusted services
* it's his/her own risk, only reliable field for IP address is $_SERVER['REMOTE_ADDR'].
*
* @var bool
*/
protected $useProxy = false; /**
* List of trusted proxy IP addresses
*
* @var array
*/
protected $trustedProxies = []; /**
* HTTP header to introspect for proxies
*
* @var string
*/
protected $proxyHeader = 'HTTP_X_FORWARDED_FOR'; /**
* Changes proxy handling setting.
*
* This must be static method, since validators are recovered automatically
* at session read, so this is the only way to switch setting.
*
* @param bool $useProxy Whether to check also proxied IP addresses.
* @return RemoteAddress
*/
public function setUseProxy($useProxy = true)
{
$this->useProxy = $useProxy;
return $this;
} /**
* Checks proxy handling setting.
*
* @return bool Current setting value.
*/
public function getUseProxy()
{
return $this->useProxy;
} /**
* Set list of trusted proxy addresses
*
* @param array $trustedProxies
* @return RemoteAddress
*/
public function setTrustedProxies(array $trustedProxies)
{
$this->trustedProxies = $trustedProxies;
return $this;
} /**
* Set the header to introspect for proxy IPs
*
* @param string $header
* @return RemoteAddress
*/
public function setProxyHeader($header = 'X-Forwarded-For')
{
$this->proxyHeader = $this->normalizeProxyHeader($header);
return $this;
} /**
* Returns client IP address.
*
* @return string IP address.
*/
public function getIpAddress()
{
$ip = $this->getIpAddressFromProxy();
if ($ip) {
return $ip;
} // direct IP address
if (isset($_SERVER['REMOTE_ADDR'])) {
$ip=$_SERVER['REMOTE_ADDR'];
if($ip="::1")
{
$ip="127.0.0.1";
} return $ip;
} return '';
} /**
* Attempt to get the IP address for a proxied client
*
* @see http://tools.ietf.org/html/draft-ietf-appsawg-http-forwarded-10#section-5.2
* @return false|string
*/
protected function getIpAddressFromProxy()
{
if (! $this->useProxy
|| (isset($_SERVER['REMOTE_ADDR']) && ! in_array($_SERVER['REMOTE_ADDR'], $this->trustedProxies))
) {
return false;
} $header = $this->proxyHeader;
if (! isset($_SERVER[$header]) || empty($_SERVER[$header])) {
return false;
} // Extract IPs
$ips = explode(',', $_SERVER[$header]);
// trim, so we can compare against trusted proxies properly
$ips = array_map('trim', $ips);
// remove trusted proxy IPs
$ips = array_diff($ips, $this->trustedProxies); // Any left?
if (empty($ips)) {
return false;
} // Since we've removed any known, trusted proxy servers, the right-most
// address represents the first IP we do not know about -- i.e., we do
// not know if it is a proxy server, or a client. As such, we treat it
// as the originating IP.
// @see http://en.wikipedia.org/wiki/X-Forwarded-For
$ip = array_pop($ips);
return $ip;
} /**
* Normalize a header string
*
* Normalizes a header string to a format that is compatible with
* $_SERVER
*
* @param string $header
* @return string
*/
protected function normalizeProxyHeader($header)
{
$header = strtoupper($header);
$header = str_replace('-', '_', $header);
if (0 !== strpos($header, 'HTTP_')) {
$header = 'HTTP_' . $header;
}
return $header;
}
} /* End of file User_agent.php */
/* Location: ./system/libraries/User_agent.php */

  

<?php

// 显示所有信息,默认显示 INFO_ALL
//phpinfo(); //如果禁用,php的配置文件php.ini,将phpinfo函数从disable_functions 中移除再重启服务器即可 // Show just the module information. 仅仅显示PHP模块信息,
// phpinfo(8) 返回同样的结果。
// phpinfo(INFO_MODULES);
// prints e.g. 'Current PHP version: 4.1.1'
echo 'Current PHP version(PHP當前版本): ' . phpversion(); // prints e.g. '2.0' or nothing if the extension isn't enabled
echo phpversion('tidy'); // print_r(ini_get_all("pcre"));
// print_r(ini_get_all());
$indicesServer = array('PHP_SELF',
'argv',
'argc',
'GATEWAY_INTERFACE',
'SERVER_ADDR',
'SERVER_NAME',
'SERVER_SOFTWARE',
'SERVER_PROTOCOL',
'REQUEST_METHOD',
'REQUEST_TIME',
'REQUEST_TIME_FLOAT',
'QUERY_STRING',
'DOCUMENT_ROOT',
'HTTP_ACCEPT',
'HTTP_ACCEPT_CHARSET',
'HTTP_ACCEPT_ENCODING',
'HTTP_ACCEPT_LANGUAGE',
'HTTP_CONNECTION',
'HTTP_HOST',
'HTTP_REFERER',
'HTTP_USER_AGENT',
'HTTPS',
'REMOTE_ADDR',
'REMOTE_HOST',
'REMOTE_PORT',
'REMOTE_USER',
'REDIRECT_REMOTE_USER',
'SCRIPT_FILENAME',
'SERVER_ADMIN',
'SERVER_PORT',
'SERVER_SIGNATURE',
'PATH_TRANSLATED',
'SCRIPT_NAME',
'REQUEST_URI',
'PHP_AUTH_DIGEST',
'PHP_AUTH_USER',
'PHP_AUTH_PW',
'AUTH_TYPE',
'PATH_INFO',
'ORIG_PATH_INFO') ; echo '<table cellpadding="10" border="1">' ;
foreach ($indicesServer as $arg) {
if (isset($_SERVER[$arg])) {
echo '<tr><td>'.$arg.'</td><td>' . $_SERVER[$arg] . '</td></tr>' ;
}
else {
echo '<tr><td>'.$arg.'</td><td>-</td></tr>' ;
}
}
echo '</table>' ; ?>

  

  

PHP: Browser, Operating System (OS), Device, and Language Detect的更多相关文章

  1. PatentTips - Method for guest operating system integrity validation

    BACKGROUND The embodiments relate to guest operating system integrity validation, and more particula ...

  2. Operating system coordinated thermal management

    A processor's performance state may be adjusted based on processor temperature. On transitions to a ...

  3. [No000035]操作系统Operating System之OS Interface操作系统接口

    接口(Interface) 仍然从常识开始… 日常生活中有很多接口:电源插座:汽车油门… 那什么是接口? 连接两个东西.信号转换.屏蔽细节… Interface: electrical circuit ...

  4. Error: 17053 LogWriter: Operating system error 21(The device is not ready.)

    今天在Detach数据库的时候出现错误,运行DBCC CHECKDB从SQL Server error log中看到下面的信息: Error: 17053, Severity: 16, State: ...

  5. 操作系统(Operating System,OS)

    操作系统(Operating System,OS) 是配置在计算机硬件上的第一层软件,是对计算机硬件系统的首次扩充,是一个计算机系统最基础,也是最重要的系统软件. 操作系统的作用 1 实现对计算机资源 ...

  6. JS: How to detect my browser version and operating system using JavaScript?

    Example: 1. for IE 11,  navigator.userAgent  returns "Mozilla/5.0 (Windows NT 6.1; WOW64; Tride ...

  7. osquery An Operating System Instrumentation Framewor

    catalog . Getting Started . install guide for OS X and Linux . Features Overview . Logging . query e ...

  8. Modern Operating System

    No one can do all things, learn to be good at use what others already did. Most computers have two m ...

  9. Single-stack real-time operating system for embedded systems

    A real time operating system (RTOS) for embedded controllers having limited memory includes a contin ...

随机推荐

  1. 附加题2 :git 简单练习

    目的: 练习git 基本操作 理解版本管理 Task 1:在码云上新建一个项目,项目命名 『Helloworld』 ,设置为公开访问. step 0: 在你计算机安装git.参照互联网教程<gi ...

  2. Lerning Entity Framework 6 ------ Handling concurrency With SQL Server Database

    The default Way to handle concurrency of Entity Framework is using optimistic concurrency. When two ...

  3. scrapy Data flow

    The data flow in Scrapy is controlled by the execution engine, and goes like this:1. The Engine gets ...

  4. javaScript 物体多形态改变加回调函数

    小方块同时改变 width height top left opacity(透明度)  加回调函数 改变第二个方块. 效果如下: <!DOCTYPE html> <html lang ...

  5. LeetCode:104_Maximum Depth of Binary Tree | 二叉树的最大深度 | Easy

    要求:求二叉树的深度(二叉树的深度为最远叶子节点到根节点的距离,即根节点到最远叶子节点的距离) Given a binary tree, find its maximum depth. The max ...

  6. Origin的使用问题集锦

    在空间上看见同学转的一篇关于学术研究的文章,由于不常常上空间,更别说在上面看一些好的文章,所以特意将那篇文章整理到自己的博客中,方便以后做科研的时候能够用到,原文出处:http://user.qzon ...

  7. spring boot -thymeleaf-日期转化

    <span th:text="${#dates.format(date)}" ></span><span th:text="${#dates ...

  8. 【sping揭秘】16、@After(finally) 但是这个实在afterturning之前执行

    package cn.cutter.start.bean; import org.apache.commons.logging.Log; import org.apache.commons.loggi ...

  9. Java高并发之线程池详解

    线程池优势 在业务场景中, 如果一个对象创建销毁开销比较大, 那么此时建议池化对象进行管理. 例如线程, jdbc连接等等, 在高并发场景中, 如果可以复用之前销毁的对象, 那么系统效率将大大提升. ...

  10. thymeleaf 的使用

    thymeleaf 语法详解1.变量输出: th:text :在页面中输出某个值 th:value :将一个值放到input标签中的value中.2.判断字符串是否为空 ①:调用内置对象一定要用# ② ...