PHP get full URL address _php tutorial

Source: Internet
Author: User
Tags php get url
The main is to get to the address bar some information, domain names, port parameters, etc.
Copy CodeThe code is as follows:
Get domain name or host address
echo $_server[' Http_host ']. "
";
Get web Address
echo $_server[' php_self ']. "
";
Get URL parameters
echo $_server["Query_string"]. "
";
Detailed address of the source page
echo $_server[' Http_referer ']. "
";
?>

PHP gets 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 Invocation method
Echo Getcururl ();

PHP Get URL address does not include path (domain name or IP address)
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 Invocation method
Echo getServerName ();

PHP get URL address contains port path
Copy CodeThe code is as follows:
Echo ' http://'. $_server[' server_name ', '. '. $_server["Server_port"].$_server["Request_uri"];

http://www.bkjia.com/PHPjc/319866.html www.bkjia.com true http://www.bkjia.com/PHPjc/319866.html techarticle The main is to get to the address bar some information, domain names, port parameters, such as copy code code as follows:? PHP//Get the domain name or host address echo $_server[' http_host '. " BR "; Get Web site ...

  • 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.