Home > Backend Development > PHP Tutorial > PHP截取当前URL并获取当前页面想要的URL信息

PHP截取当前URL并获取当前页面想要的URL信息

PHPz
Release: 2020-12-04 14:20:23
forward
2374 people have browsed it

PHP截取当前URL并获取当前页面想要的URL信息

推荐:《PHP视频教程

在PHP中获取当前页面的URL信息

<?  
//获取当前的域名:  
echo $_SERVER[&#39;SERVER_NAME&#39;];  
//获取来源网址,即点击来到本页的上页网址  
echo $_SERVER["HTTP_REFERER"];  
$_SERVER[&#39;REQUEST_URI&#39;];//获取当前域名的后缀  
$_SERVER[&#39;HTTP_HOST&#39;];//获取当前域名  
dirname(__FILE__);//获取当前文件的物理路径  
dirname(__FILE__)."/../";//获取当前文件的上一级物理路径  
?>
Copy after login
#测试网址:     http://www.php.cn/blog/test.php?act=checkcode

//获取域名或主机地址 
echo $_SERVER[&#39;HTTP_HOST&#39;]."<br>"; #www.php.cn

//获取网页地址 
echo $_SERVER[&#39;PHP_SELF&#39;]."<br>"; #/blog/test.php

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

//获取用户代理 
echo $_SERVER[&#39;HTTP_REFERER&#39;]."<br>"; 

//获取完整的url
echo &#39;http://&#39;.$_SERVER[&#39;HTTP_HOST&#39;].$_SERVER[&#39;REQUEST_URI&#39;];
echo &#39;http://&#39;.$_SERVER[&#39;HTTP_HOST&#39;].$_SERVER[&#39;PHP_SELF&#39;].&#39;?&#39;.$_SERVER[&#39;QUERY_STRING&#39;];
# http://www.php.cn/blog/test.php?act=checkcode

//包含端口号的完整url
echo &#39;http://&#39;.$_SERVER[&#39;SERVER_NAME&#39;].&#39;:&#39;.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; 
# http://www.php.cn:80/blog/test.php?act=checkcode

//只取路径
$url=&#39;http://&#39;.$_SERVER[&#39;SERVER_NAME&#39;].$_SERVER["REQUEST_URI"]; 
echo dirname($url);
#http://www.php.cn:80/blog
Copy after login

 

Related labels:
source:csdn.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template