Home  >  Article  >  Backend Development  >  PHP Get current URL

PHP Get current URL

巴扎黑
巴扎黑Original
2016-11-08 11:21:061445browse

<!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>

PHP Get current URL

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn