Obtain the url of the current page. php code _ PHP Tutorial

Source: Internet
Author: User
Obtain the php code of the url address of the current page. Obtain the php code of the url address of the current page. The first is a method for obtaining a URL without parameters. The second is to obtain the complete URL function. if you are looking for the url parameter code. Obtain the url of the current page to obtain the url of the current page. php code: The first is to obtain a URL without parameters. The second is to obtain the complete URL function, if you are looking for the url parameter code.

Obtain the php Tutorial code of the url address of the current page. The first is to obtain the complete url function. if you are looking for the url parameter code.

// Description: obtain a url without parameters.

Function curpageurl ()
{
$ Pageurl = 'http ';

If ($ _ server ["https tutorial"] = "on ")
{
$ Pageurl. = "s ";
}
$ Pageurl. = "://";

If ($ _ server ["server_port"]! = "80 ")
{
$ Pageurl. = $ _ server ["server_name"]. ":". $ _ server ["server_port"]. $ _ server ['php _ self '];
}
Else
{
$ Pageurl. = $ _ server ["server_name"]. $ _ server ['php _ self '];
}
Return $ pageurl;
}
?>

Method 2

// Description: obtain the complete url

Function curpageurl ()
{
$ Pageurl = 'http ';

If ($ _ server ["https"] = "on ")
{
$ 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;
}
?>

In addition, $ _ server ['request _ url'] and $ _ server ['request _ url'] are slightly different:
$ _ Server ["request_uri"] returns the complete path (/directory/file. ext? Query = string)
$ _ Server ['request _ url'] returns only the file path, excluding parameters (/directory/file. ext), similar to $ _ server ['php _ self '], except that $ _ server ['request _ url'] is unavailable on some servers.

Bytes. Get the url of the current page...

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.