首页  >  文章  >  后端开发  >  PHP 获取当前 URL

PHP 获取当前 URL

巴扎黑
巴扎黑原创
2016-12-07 13:55:542089浏览

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>PHP中获取当前URL</title>
</head>
<body>
<script type="text/javascript">
var a = top.location.href;   //顶级窗口的地址
var b = this.location.href;  //当前窗口的地址
document.write(&#39;顶级窗口的地址:&#39;+a+&#39;<br>当前窗口的地址:&#39;+b+&#39;<br><br>&#39;);
</script>
<?php 
//测试网站:http://localhost/webManage/demo.php?f=onestopweb.cn
echo &#39;获取域名或主机地址:<br>&#39;;
echo $_SERVER[&#39;HTTP_HOST&#39;]."<br>";
echo &#39;获取网页地址:<br>&#39;;
echo $_SERVER[&#39;PHP_SELF&#39;]."<br>";
echo &#39;获取网址参数:<br>&#39;;
echo $_SERVER["QUERY_STRING"]."<br>";
echo &#39;获取完整的url:<br>&#39;;
echo &#39;http://&#39;.$_SERVER[&#39;HTTP_HOST&#39;].$_SERVER[&#39;REQUEST_URI&#39;]."<br>";
echo &#39;http://&#39;.$_SERVER[&#39;HTTP_HOST&#39;].$_SERVER[&#39;PHP_SELF&#39;].&#39;?&#39;.$_SERVER[&#39;QUERY_STRING&#39;]."<br>";
echo &#39;包含端口号的完整url:<br>&#39;;
echo &#39;http://&#39;.$_SERVER[&#39;SERVER_NAME&#39;].&#39;:&#39;.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]."<br>";
$url=&#39;http://&#39;.$_SERVER[&#39;SERVER_NAME&#39;].$_SERVER["REQUEST_URI"]."<br>";
echo dirname($url);
?>
</body>
</html>

效果图:

e6c3613e-a57e-3ee1-bf24-bb328b4e4e3c.png

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn