Obtain the url of the current page. php code

Source: Internet
Author: User
Get the url of the current page php Tutorial code, the first is a get url without parameters, the second is to get the complete url function

Get the url of the current page php Tutorial code. The first is a get url without parameters, and the second is to get the complete url function.

Method 1:

  1. // Description: obtain a url without parameters.
  2. Function curpageurl ()
  3. {
  4. $ Pageurl = 'http ';
  5. If ($ _ server ["https tutorial"] = "on ")
  6. {
  7. $ Pageurl. = "s ";
  8. }
  9. $ Pageurl. = "://";
  10. If ($ _ server ["server_port"]! = "80 ")
  11. {
  12. $ Pageurl. = $ _ server ["server_name"]. ":". $ _ server ["server_port"]. $ _ server ['php _ self '];
  13. }
  14. Else
  15. {
  16. $ Pageurl. = $ _ server ["server_name"]. $ _ server ['php _ self '];
  17. }
  18. Return $ pageurl;
  19. }
  20. ?>

Method 2

  1. // Description: obtain the complete url
  2. Function curpageurl ()
  3. {
  4. $ Pageurl = 'http ';
  5. If ($ _ server ["https"] = "on ")
  6. {
  7. $ Pageurl. = "s ";
  8. }
  9. $ Pageurl. = "://";
  10. If ($ _ server ["server_port"]! = "80 ")
  11. {
  12. $ Pageurl. = $ _ server ["server_name"]. ":". $ _ server ["server_port"]. $ _ server ["request_uri"];
  13. }
  14. Else
  15. {
  16. $ Pageurl. = $ _ server ["server_name"]. $ _ server ["request_uri"];
  17. }
  18. Return $ pageurl;
  19. }
  20. ?>

In addition, $ _ server ['request _ url'] and $ _ server ['request _ url'] are slightly different:

$ _ Server ["request_uri"] returns the complete path (/directory/file. ext? Query = string)

$ _ Server ['request _ url'] returns only the file path, excluding parameters (/directory/file. ext), similar to $ _ server ['php _ self '], except that $ _ server ['request _ url'] is unavailable on some servers.

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.