获取域名等信息
<?
//获取当前的域名:
echo $_SERVER['SERVER_NAME'];
//获取来源网址,即点击来到本页的上页网址
echo $_SERVER["HTTP_REFERER"];
$_SERVER['REQUEST_URI'];//获取当前域名...
获取域名等信息
<?
//获取当前的域名:
echo $_SERVER['SERVER_NAME'];
//获取来源网址,即点击来到本页的上页网址
echo $_SERVER["HTTP_REFERER"];
$_SERVER['REQUEST_URI'];//获取当前域名的后缀
$_SERVER['HTTP_HOST'];//获取当前域名
dirname(__FILE__);//获取当前文件的物理路径
dirname(__FILE__)."/../";//获取当前文件的上一级物理路径
?>
获取浏览器ua
<?php
//显示访问用户的浏览器信息
echo 'Browser: ' . determinebrowser($Agent) . '<BR>';
//显示访问用户的操作系统平台
echo 'Platform: ' . determineplatform($Agent). '<BR>';
//正值表达式比对解析$_SERVER['HTTP_USER_AGENT']中的字符串 获取访问用户的浏览器的信息
function determinebrowser ($Agent) {
$browseragent=""; //浏览器
$browserversion=""; //浏览器的版本
if (ereg('MSIE ([0-9].[0-9]{1,2})',$Agent,$version)) {
$browserversion=$version[1];
$browseragent="Internet Explorer";
} else if (ereg( 'Opera/([0-9]{1,2}.[0-9]{1,2})',$Agent,$version)) {
$browserversion=$version[1];
$browseragent="Opera";
} else if (ereg( 'Firefox/([0-9.]{1,5})',$Agent,$version)) {
$browserversion=$version[1];
$browseragent="Firefox";
}else if (ereg( 'Chrome/([0-9.]{1,3})',$Agent,$version)) {
$browserversion=$version[1];
$browseragent="Chrome";
}
else if (ereg( 'Safari/([0-9.]{1,3})',$Agent,$version)) {
$browseragent="Safari";
$browserversion="";
}
else {
$browserversion="";
$browseragent="Unknown";
}
return $browseragent." ".$browserversion;
}
// 同理获取访问用户的浏览器的信息
function determineplatform ($Agent) {
$browserplatform=='';
if (eregi('win',$Agent) && strpos($Agent, '95')) {
$browserplatform="Windows 95";
}
elseif (eregi('win 9x',$Agent) && strpos($Agent, '4.90')) {
$browserplatform="Windows ME";
}
elseif (eregi('win',$Agent) && ereg('98',$Agent)) {
$browserplatform="Windows 98";
}
elseif (eregi('win',$Agent) && eregi('nt 5.0',$Agent)) {
$browserplatform="Windows 2000";
}
elseif (eregi('win',$Agent) && eregi('nt 5.1',$Agent)) {
$browserplatform="Windows XP";
}
elseif (eregi('win',$Agent) && eregi('nt 6.0',$Agent)) {
$browserplatform="Windows Vista";
}
elseif (eregi('win',$Agent) && eregi('nt 6.1',$Agent)) {
$browserplatform="Windows 7";
}
elseif (eregi('win',$Agent) && ereg('32',$Agent)) {
$browserplatform="Windows 32";
}
elseif (eregi('win',$Agent) && eregi('nt',$Agent)) {
$browserplatform="Windows NT";
}elseif (eregi('Mac OS',$Agent)) {
$browserplatform="Mac OS";
}
elseif (eregi('linux',$Agent)) {
$browserplatform="Linux";
}
elseif (eregi('unix',$Agent)) {
$browserplatform="Unix";
}
elseif (eregi('sun',$Agent) && eregi('os',$Agent)) {
$browserplatform="SunOS";
}
elseif (eregi('ibm',$Agent) && eregi('os',$Agent)) {
$browserplatform="IBM OS/2";
}
elseif (eregi('Mac',$Agent) && eregi('PC',$Agent)) {
$browserplatform="Macintosh";
}
elseif (eregi('PowerPC',$Agent)) {
$browserplatform="PowerPC";
}
elseif (eregi('AIX',$Agent)) {
$browserplatform="AIX";
}
elseif (eregi('HPUX',$Agent)) {
$browserplatform="HPUX";
}
elseif (eregi('NetBSD',$Agent)) {
$browserplatform="NetBSD";
}
elseif (eregi('BSD',$Agent)) {
$browserplatform="BSD";
}
elseif (ereg('OSF1',$Agent)) {
$browserplatform="OSF1";
}
elseif (ereg('IRIX',$Agent)) {
$browserplatform="IRIX";
}
elseif (eregi('FreeBSD',$Agent)) {
$browserplatform="FreeBSD";
}
if ($browserplatform=='') {$browserplatform = "Unknown"; }
return $browserplatform;
}
?>
判断浏览器名称及语言
浏览器名称
<?php
if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 8.0"))
echo "Internet Explorer 8.0";
else if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 7.0"))
echo "Internet Explorer 7.0";
else if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 6.0"))
echo "Internet Explorer 6.0";
else if(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox/3"))
echo "Firefox 3";
else if(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox/2"))
echo "Firefox 2";
else if(strpos($_SERVER["HTTP_USER_AGENT"],"Chrome"))
echo "Google Chrome";
else if(strpos($_SERVER["HTTP_USER_AGENT"],"Safari"))
echo "Safari";
else if(strpos($_SERVER["HTTP_USER_AGENT"],"Opera"))
echo "Opera";
else echo $_SERVER["HTTP_USER_AGENT"];
?>
语言信息
<?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4); //只取前4位,这样只判断最优先的语言。如果取前5位,可能出现en,zh的情况,影响判断。
if (preg_match("/zh-c/i", $lang))
echo "简体中文";
else if (preg_match("/zh/i", $lang))
echo "繁體中文";
else if (preg_match("/en/i", $lang))
echo "English";
else if (preg_match("/fr/i", $lang))
echo "French";
else if (preg_match("/de/i", $lang))
echo "German";
else if (preg_match("/jp/i", $lang))
echo "Japanese";
else if (preg_match("/ko/i", $lang))
echo "Korean";
else if (preg_match("/es/i", $lang))
echo "Spanish";
else if (preg_match("/sv/i", $lang))
echo "Swedish";
else echo $_SERVER["HTTP_ACCEPT_LANGUAGE"];
?>