Php web path retrieval

Source: Internet
Author: User
Php web path retrieval

  1. Class HttpTool
  2. {
  3. /**
  4. * // Obtain the domain name or host address
  5. * # Test URL: http: // localhost: 8081/test/testurl. php? Id = 5
  6. * Returns localhost: 8081.
  7. */
  8. Public function getHost ()
  9. {
  10. Return $ _ SERVER ['http _ host'];
  11. }
  12. /**
  13. * Url of the current page (including parameters)
  14. */
  15. Public function getWebUrl ()
  16. {
  17. $ PageURL = 'http ';
  18. If (isset ($ _ SERVER ["HTTPS"]) & $ _ SERVER ["HTTPS"] = "on ")
  19. {
  20. $ PageURL. = "s ";
  21. }
  22. $ PageURL. = "://";
  23. $ PageURL. = $ _ SERVER ['http _ host']. $ _ SERVER ['request _ URI '];
  24. Return $ pageURL;
  25. }
  26. /**
  27. *
  28. * Url of the current page (excluding parameters)
  29. */
  30. Public function getWebPath ()
  31. {
  32. $ PageURL = 'http ';
  33. If (isset ($ _ SERVER ["HTTPS"]) & $ _ SERVER ["HTTPS"] = "on ")
  34. {
  35. $ PageURL. = "s ";
  36. }
  37. $ PageURL. = "://";
  38. $ PageURL. = $ _ SERVER ['http _ host']. $ _ SERVER ['php _ SELF '];
  39. Return $ pageURL;
  40. }
  41. /**
  42. * Parent path of the current page
  43. */
  44. Public function getWebParentPath ()
  45. {
  46. $ PageURL = 'http ';
  47. If (isset ($ _ SERVER ["HTTPS"]) & $ _ SERVER ["HTTPS"] = "on ")
  48. {
  49. $ PageURL. = "s ";
  50. }
  51. $ PageURL. = "://";
  52. $ PageURL. = $ _ SERVER ['http _ host']. $ _ SERVER ['php _ SELF '];
  53. $ PageURL = substr ($ pageURL, 0, strrpos ($ pageURL ,"/"));
  54. Return $ pageURL;
  55. }
  56. /**
  57. * Server name
  58. */
  59. Public function getServerName ()
  60. {
  61. Return $ _ SERVER ['server _ name'];
  62. }
  63. /**
  64. * Port
  65. */
  66. Public function getServerPort ()
  67. {
  68. Return $ _ SERVER ["SERVER_PORT"];
  69. }
  70. /**
  71. * Link parameter, question mark? Parameters after
  72. */
  73. Public function getQueryString ()
  74. {
  75. Return $ _ SERVER ['query _ string'];
  76. }
  77. /**
  78. * The request address. the returned value is not the host content.
  79. */
  80. Public function getRequestUri ()
  81. {
  82. Return $ _ SERVER ['request _ URI '];
  83. }
  84. }
  85. $ Http = new HttpTool ();
  86. Echo "host ====================". $ http-> getHost ()."
    ";
  87. Echo "weburl ==============". $ http-> getWebUrl ()."
    ";
  88. Echo "webPath ============". $ http-> getWebPath ()."
    ";
  89. Echo "getWebParentPath =". $ http-> getWebParentPath ()."
    ";
  90. Echo "getServerName ====". $ http-> getServerName ()."
    ";
  91. Echo "getServerPort ====". $ http-> getServerPort ()."
    ";
  92. Echo "getQueryString ====". $ http-> getQueryString ()."
    ";
  93. Echo "getRequestUri ====". $ http-> getRequestUri ()."
    ";
  94. ?>


Test URL: http: // localhost: 8081/test/httptool. php? Name = penngo

Output result:

Host =================== localhost: 8081
Weburl ============== http: // localhost: 8081/test/httptool. php? Name = penngo
WebPath ============= http: // localhost: 8081/test/httptool. php
GetWebParentPath = http: // localhost: 8081/test
GetServerName ===== localhost
GetServerPort ===== 8081
GetQueryString ==== name = penngo
GetRequestUri =====/ test/httptool. php? Name = penngo

Php, web

Related Article

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.