Home >Backend Development >PHP Tutorial >Get the url address php code of the current page_PHP tutorial

Get the url address php code of the current page_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:58:07815browse

Get the url address php code of the current page. The first one is to get the URL without parameters. The second one is to get the complete URL function. If you are looking for the code of url parameters.

Get the url address of the current page php tutorial code, the first one is to get the url without parameters, the second one is to get the complete url function, if you are looking for the code of url parameters.

// Description: Get 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 2

// Description: Get 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_uri'] and $_server['request_url'] are slightly different:
$_server["request_uri"] returns the complete path ( /directory/file.ext?query=string )
$_server['request_url'] only returns the file path, excluding parameters, (/directory/file.ext), which is similar to $_server['php_self'], except that $_server['request_url'] is not available on some servers

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632035.htmlTechArticleGet the url address php code of the current page. The first one is to get the parameterless URL. The second one is to get the url address of the current page. Complete URL function, if you are looking for the code of url parameters. Get the URL of the current page...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn