PHP Gets the current page complete URL method _javascript Tips

Source: Internet
Author: User

First, use JavaScript to achieve:

top.location.hrefAddress of the top-level window

this.location.hrefThe 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.