Home > Article > Backend Development > php get the complete url address
Mainly get some information from the address bar, domain name, port parameters, etc.
<?php //获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br>"; //获取网页地址 echo $_SERVER['PHP_SELF']."<br>"; //获取网址参数 echo $_SERVER["QUERY_STRING"]."<br>"; //来源网页的详细地址 echo $_SERVER['HTTP_REFERER']."<br>"; ?>
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();
php Get the url address without the path ( Domain name or IP address)
function getServerName() { $ServerName = strtolower($_SERVER['SERVER_NAME']?$_SERVER['SERVER_NAME']:$_SERVER['HTTP_HOST']); if( strpos($ServerName,'http://') ) { return str_replace('http://','',$ServerName); } return $ServerName; } //实例调用方法 echo getServerName();
php Get the url address including the port path
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
For more php Get the complete url address related articles, please pay attention to the PHP Chinese website!