PHP get current page URL function instance _php tips

Source: Internet
Author: User

This article describes the PHP to get the current page URL function example, share for everyone to reference. The implementation methods are as follows:

In PHP, there is no default function to get the URL of the current page, so today we're going to introduce you to a PHP function that gets the full URL of the current page in PHP.

The function code is as follows, the call only need to use Curpageurl () on the line:

Copy Code code as follows:
/* Get the current page URL start * *
function Curpageurl () {
$pageURL = ' http ';
if ($_server["HTTPS"] = = "on") {//If SSL encryption plus "s"
$pageURL. = "S";
}
$pageURL. = "://";
if ($_server["Server_port"]!= "80") {
$pageURL. = $_server["SERVER_NAME"]. ":" $_server["Server_port"].$_server["Request_uri"];
} else {
$pageURL. = $_server["SERVER_NAME"].$_server["Request_uri"];
}
return $pageURL;
}
/* Get current Page URL End * *

To add the server parameter description, the code is as follows:

Copy Code code as follows:
Echo $_server[' Http_host ']. " <br> "; #localhost
 
//Get page address  
Echo $_server[' php_self ']. " <br> "; #/blog/testurl.php
 
//Get URL parameters  
echo $_server["Query_string"]. " <br> "; #id =5
 
//Get user agent  
Echo $_server[' Http_referer ']. " <br> ";
 
//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/blog/testurl.php?id=5
 
//full URL containing port number
Echo ' http://'. $_server[' server_name ']. ': '. $_server["Server_port"].$_server["Request_uri"]; 
#http://localhost:80/blog/testurl.php?id=5
//Only fetch path
$url = ' http://'. $_server[' server_name '].$_server[' Request_uri ']; 
Echo dirname ($url);
#http://localhost/blog

I hope this article will help you with your PHP program design.

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.