网站推广.NET

网站推广.NET

PHP 获取当前 URL

来源:互联网

<!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.cnecho &#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获取当前url