// 根目录的路径
$_SERVER['DOCUMENT_ROOT']
//获取域名或主机地址
echo $_SERVER['HTTP_HOST']."
"; #jiqing.nikon.comecho 'http://'.$_SERVER['HTTP_HOST'].'/'; #http://jiqing.nikon.com/
//获取网页地址
echo $_SERVER['PHP_SELF']."
"; #/Home/picture
//获取网址参数
echo $_SERVER["QUERY_STRING"]."
"; #machine_type_id=2
//获取用户代理
echo $_SERVER['HTTP_REFERER']."
"; #http://jiqing.nikon.com/index.php/Home/index
//获取完整的url
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."
"; # http://jiqing.nikon.com/index.php/Home/picture?machine_type_id=2echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."
"; #http://jiqing.nikon.com/Home/picture?machine_type_id=2
//包含端口号的完整url
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]."
";#http://jiqing.nikon.com:80/index.php/Home/picture?machine_type_id=2
//只取路径
echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]."
"; # http://jiqing.nikon.com/index.php/Home
应用案例,根据浏览器类型,自动切换
vendor('Func.Func');if (!Func::isMobile()) { // 跳转到手机端
if ($_SERVER['QUERY_STRING']) { header("location: /index.php".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
} else { header("location: /index.php".$_SERVER['PHP_SELF']);
}
}