<!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('顶级窗口的地址:'+a+'<br>当前窗口的地址:'+b+'<br><br>');</script><?php //测试网站:http://localhost/webManage/demo.php?f=onestopweb.cnecho '获取域名或主机地址:<br>';echo $_SERVER['HTTP_HOST']."<br>";echo '获取网页地址:<br>';echo $_SERVER['PHP_SELF']."<br>";echo '获取网址参数:<br>';echo $_SERVER["QUERY_STRING"]."<br>";echo '获取完整的url:<br>';echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."<br>";echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."<br>";echo '包含端口号的完整url:<br>';echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]."<br>";$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]."<br>";echo dirname($url);?></body></html>
效果图:
免责声明:本站内容仅用于学习参考,信息和图片素材来源于互联网,如内容侵权与违规,请联系我们进行删除,我们将在三个工作日内处理。联系邮箱:chuangshanghai#qq.com(把#换成@)