加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP判断浏览器、判断语言代码分享

发布时间:2020-12-12 20:43:33 所属栏目:PHP教程 来源:网络整理
导读:PHP编程中经常需要用到一些服务器的一些资料,特把$_SERVER的详细参数整理下,方便以后使用。 判断浏览器类型 判断语言 判断浏览器内核的PHP程序 function getIP () { global $_SERVER; if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); }

PHP编程中经常需要用到一些服务器的一些资料,特把$_SERVER的详细参数整理下,方便以后使用。

判断浏览器类型

判断语言

判断浏览器内核的PHP程序

function getIP ()
{
global $_SERVER;
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'];
}
return $ip;
}

function getOS ()
{
global $_SERVER;
$agent = $_SERVER['HTTP_USER_AGENT'];
$os = false;
if (preg_match('/win/',$agent) && strpos($agent,'95')){
$os = 'Windows 95';
}
else if (preg_match('/win 9x/','4.90')){
$os = 'Windows ME';
}
else if (preg_match('/win/',$agent) && preg_match('98',$agent)){
$os = 'Windows 98';
}
else if (preg_match('/win/',$agent) && preg_match('nt 5.1',$agent)){
$os = 'Windows XP';
}
else if (preg_match('/win/',$agent) && preg_match('nt 5',$agent)){
$os = 'Windows 2000';
}
else if (preg_match('/win/',$agent) && preg_match('nt',$agent)){
$os = 'Windows NT';
}
else if (preg_match('/win/',$agent) && preg_match('32',$agent)){
$os = 'Windows 32';
}
else if (preg_match('/linux/',$agent)){
$os = 'Linux';
}
else if (preg_match('/unix/',$agent)){
$os = 'Unix';
}
else if (preg_match('/sun/',$agent) && preg_match('os',$agent)){
$os = 'SunOS';
}
else if (preg_match('/ibm/',$agent)){
$os = 'IBM OS/2';
}
else if (preg_match('/Mac/',$agent) && preg_match('PC',$agent)){
$os = 'Macintosh';
}
else if (preg_match('/PowerPC/',$agent)){
$os = 'PowerPC';
}
else if (preg_match('/AIX/',$agent)){
$os = 'AIX';
}
else if (preg_match('/HPUX/',$agent)){
$os = 'HPUX';
}
else if (preg_match('/NetBSD/',$agent)){
$os = 'NetBSD';
}
else if (preg_match('/BSD/',$agent)){
$os = 'BSD';
}
else if (preg_match('/OSF1/',$agent)){
$os = 'OSF1';
}
else if (preg_match('/IRIX/',$agent)){
$os = 'IRIX';
}
else if (preg_match('/FreeBSD/',$agent)){
$os = 'FreeBSD';
}
else if (preg_match('/teleport/',$agent)){
$os = 'teleport';
}
else if (preg_match('/flashget/',$agent)){
$os = 'flashget';
}
else if (preg_match('/webzip/',$agent)){
$os = 'webzip';
}
else if (preg_match('/offline/',$agent)){
$os = 'offline';
}
else {
$os = 'Unknown';
}
return $os;
}
}
$code = new clientGetObj;
echo $str1 = $code->getBrowse()."
";//浏览器:
echo $str2 = $code->getIP()."
";//IP地址:
echo $str3 = $code->getOS();//操作系统:
?>

以上就是个人整理的关于$_SERVER获取服务器信息的常用信息了,希望大家能够喜欢。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读