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