PHP obtains the complete URL

Source: Internet
Author: User

It mainly obtains some information about the address bar, domain names, port parameters, etc.

CopyCode The Code is as follows: <? PHP
// Obtain the domain name or host address
Echo $ _ server ['HTTP _ host']. "<br> ";
// Obtain the webpage address
Echo $ _ server ['php _ Self ']. "<br> ";
// Obtain URL parameters
Echo $ _ server ["QUERY_STRING"]. "<br> ";
// Detailed address of the source webpage
Echo $ _ server ['HTTP _ referer']. "<br> ";
?>

PHP obtains the current Script URL (only path)Copy codeThe 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)Copy codeThe 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 containing the port path copy Code the code is as follows: Echo 'HTTP ://'. $ _ server ['server _ name']. ':'. $ _ server ["server_port"]. $ _ server ["request_uri"];

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.