note 114753 deleted from function.http-build-url by sobak
| From: | sobak@php.net | Date: | Sun, 04 Dec 2016 07:19:56 +0000 |
| Subject: | note 114753 deleted from function.http-build-url by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208040@lists.php.net to get a copy of this message | ||
Note Submitter: michael at REMOVE-THIS-PART dot muryn dot name
----
To those that want to use http_build_url() without parameters to get the canonical page URL, be
aware that this function seem to consider the equivalent of SCRIPT_NAME for the path instead of
REQUEST_URI.
For example, if /example serve info.php (you can do this with mod_rewrite in Apache for example),
while accessing http://example.com/example?test=1
this function will return http://example.com/info.php?test=1 instead of the URL
the user see. This could lead to obvious problems if you build other URL from this.
So like another comment say, it is reckless to use that undocumented feature. Instead here is what
I suggest:
<?php
function get_request_url()
{
return get_request_scheme() . '://' . $_SERVER['HTTP_HOST'] .
$_SERVER['REQUEST_URI'];
}
function get_request_scheme()
{
return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !==
'off') ? 'https' : 'http';
}
?>