php如何获取当前页面地址 完整的url网址

作者:MJ 发布于:2019-12-26 11:17 Thursday 分类:PHP

//获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br />"; #mj.588cy.com

//获取网页地址 echo $_SERVER['PHP_SELF']."<br />"; #/php/3299.php

//获取网址参数 echo $_SERVER["QUERY_STRING"]."<br />"; #id=1

//获取用户代理 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'];#http://mj.588cy.com/php/3299.php?id=1

//包含端口号的完整url echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
#http://mj.588cy.com:80/php/3299.php?id=1
//只取路径
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];echo dirname($url);

#http://mj.588cy.com/php



javascript获取url: top.location.href 顶级窗口的地址 this.location.href 当前窗口的地址

标签: php

»

发表评论:

Powered by 588cy.com