First, use JavaScript to achieve:
top.location.href
Address of the top-level window
this.location.href
The address of the current window
Second, the use of PHP to achieve
Http://localhost/PHP/XX.php?id=5
Get domain name or host address
echo $_server[' Http_host ']; #localhost
Get Web page address
echo $_server[' php_self ']; #/php/xx.php
Get URL parameters
echo $_server["Query_string"]; #id =5
Get user Agent
Get the full URL
echo ' http://'. $_server[' http_host '].$_server[' Request_uri ';
echo ' http://' $_server[' http_host '].$_server[' php_self '. $_server[' query_string '];
#http://localhost/php/xx.php?id=5
Full URL that contains the port number
echo ' http://'. $_server[' server_name ']. ': $_server[' server_port '].$_server[' Request_uri ';
#http://localhost:80/php/xx.php?id=5
Fetch path only
$url = ' http://'. $_server[' server_name '].$_server[' Request_uri '];
echo dirname ($url);
#http://localhost/php
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.