php get the complete url address

高洛峰
Release: 2023-03-04 18:56:01
Original
3492 people have browsed it

Mainly get some information from the address bar, domain name, port parameters, etc.

<?php 
//获取域名或主机地址 
echo $_SERVER[&#39;HTTP_HOST&#39;]."<br>"; 
//获取网页地址 
echo $_SERVER[&#39;PHP_SELF&#39;]."<br>"; 
//获取网址参数 
echo $_SERVER["QUERY_STRING"]."<br>"; 
//来源网页的详细地址 
echo $_SERVER[&#39;HTTP_REFERER&#39;]."<br>"; 
?>
Copy after login

php Get the current script URL (only the path)

function GetCurUrl() 
{ 
if(!empty($_SERVER["REQUEST_URI"])) 
{ 
$scrtName = $_SERVER["REQUEST_URI"]; 
$nowurl = $scrtName; 
} 
else 
{ 
$scrtName = $_SERVER["PHP_SELF"]; 
if(empty($_SERVER["QUERY_STRING"])) 
{ 
$nowurl = $scrtName; 
} 
else 
{ 
$nowurl = $scrtName."?".$_SERVER["QUERY_STRING"]; 
} 
} 
return $nowurl; 
} 
//实例调用方法 
//echo GEtCurUrl();
Copy after login

php Get the url address without the path ( Domain name or IP address)

function getServerName() 
{ 
$ServerName = strtolower($_SERVER[&#39;SERVER_NAME&#39;]?$_SERVER[&#39;SERVER_NAME&#39;]:$_SERVER[&#39;HTTP_HOST&#39;]); 
if( strpos($ServerName,&#39;http://&#39;) ) 
{ 
return str_replace(&#39;http://&#39;,&#39;&#39;,$ServerName); 
} 
return $ServerName; 
} 
//实例调用方法 
echo getServerName();
Copy after login

php Get the url address including the port path

echo &#39;http://&#39;.$_SERVER[&#39;SERVER_NAME&#39;].&#39;:&#39;.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
Copy after login

For more php Get the complete url address related articles, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!