对于很多新手PHP程序猿来说,PHP很多功能都不是很熟络,就像现在说到的,PHP如何获得浏览器地址呢?
//获取域名或主机地址
echo $_SERVER['HTTP_HOST']."<br>"; #localhost
//获取网页地址
echo $_SERVER['PHP_SELF']."<br>"; #/testurl.PHP
//获取网址参数
echo $_SERVER["QUERY_STRING"]."<br>"; #id=3
//获取用户代理
echo $_SERVER['HTTP_REFERER']."<br>";
//获取完整的url
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
#https://www.xiaobinblog.com/testurl.PHP?id=3
//包含端口号的完整url
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
#https://www.xiaobinblog.com:80/testurl.PHP?id=5
//只取路径
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
本文来自投稿,不代表本站立场,如若转载,请注明出处:https://www.xiaobinblog.com/1029.html
发表评论