Php getting complete url address _ PHP Tutorial

Source: Internet
Author: User
Php obtains the complete url address. The following code copies information, domain names, port parameters, and other information in the address bar :? Php obtains the domain name or host address echo $ _ SERVER [HTTP_HOST]. br. the webpage mainly obtains some information in the address bar, such as the domain name and port parameters.

The code is as follows:


// Obtain the domain name or host address
Echo $ _ SERVER ['http _ host']."
";
// Obtain the webpage address
Echo $ _ SERVER ['php _ SELF ']."
";
// Obtain URL parameters
Echo $ _ SERVER ["QUERY_STRING"]."
";
// Detailed address of the source webpage
Echo $ _ SERVER ['http _ referer']."
";
?>


Php obtains the current script URL (only Path)

The code is as follows:


Function GetCurUrl ()
{
If (! Empty ($ _ SERVER ["REQUEST_URI"])
{
$ ScrtName = $ _ SERVER ["REQUEST_URI"];
$ Nowurl = $ scrtName;
}
Else
{
$ ScrtName = $ _ SERVER ["PHP_SELF"];
If (empty ($ _ SERVER ["QUERY_STRING"])
{
$ Nowurl = $ scrtName;
}
Else
{
$ Nowurl = $ scrtName ."? ". $ _ SERVER [" QUERY_STRING "];
}
}
Return $ nowurl;
}
// Instance call method
// Echo GEtCurUrl ();


Php retrieves url addresses without paths (domain names or IP addresses)

The code is as follows:


Function getServerName ()
{
$ ServerName = strtolower ($ _ SERVER ['server _ name']? $ _ SERVER ['server _ name']: $ _ SERVER ['http _ host']);
If (strpos ($ ServerName, 'http ://'))
{
Return str_replace ('http: // ', '', $ ServerName );
}
Return $ ServerName;
}
// Instance call method
Echo getServerName ();


Php obtains the url address, including the port path.

The code is as follows:


Echo 'http ://'. $ _ SERVER ['server _ name']. ':'. $ _ SERVER ["SERVER_PORT"]. $ _ SERVER ["REQUEST_URI"];

The pipeline code is as follows :? Php // Obtain the domain name or HOST address echo $ _ SERVER ['http _ host']. "br"; // Obtain the webpage location...

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.