How to get url in php without parameters: 1. Get the domain name or host address through "$_SERVER['HTTP_HOST']"; 2. Get the web page address through "$_SERVER['PHP_SELF']" .
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to get the url in php without parameters?
Test URL:
http://afish.cnblogs.com/p/3941211.html?id=1
The PHP code is implemented as follows:
//获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br />"; #afish.cnblogs.com //获取网页地址 echo $_SERVER['PHP_SELF']."<br />"; #/p/3941211.html //获取网址参数 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://afish.cnblogs.com/p/3941211.html?id=1 //包含端口号的完整url echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; #http://afish.cnblogs.com:80/p/3941211.html?id=1 //只取路径 $url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; echo dirname($url); #http://afish.cnblogs.com/p
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to get url in php without parameters. For more information, please follow other related articles on the PHP Chinese website!