Get the current page URL address php code

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags .url address code file function get http https

The first paragraph is a get url without parameters The second paragraph is to get the complete url function Oh, if you are looking for url parameter code Oh.

<? php
// Description: Get the parameterless url

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 Two

<? php
// Description: Get the full 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, there is a slight difference between $ _ server ['request_uri'] and $ _server ['request_url']:
$ _server ["request_uri"] returns the full path (/directory/file.ext?query=string)
$ _server ['request_url'] only returns the path of the file, excluding parameters (/directory/file.ext), which is about the same as $ _server ['php_self'], except that on some servers $ _server ['request_url'] is not available

Related Article

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.