note 114753 added to function.http-build-url

From: Date: Tue, 01 Apr 2014 23:16:39 +0000
Subject: note 114753 added to function.http-build-url
Groups: php.notes 
Request: Send a blank email to php-notes+get-199098@lists.php.net to get a copy of this message
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'; } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 69.157.84.184 ---- Manual Page -- http://php.net/manual/en/function.http-build-url.php Edit -- https://master.php.net/note/edit/114753 Del: integrated -- https://master.php.net/note/delete/114753/integrated Del: useless -- https://master.php.net/note/delete/114753/useless Del: bad code -- https://master.php.net/note/delete/114753/bad+code Del: spam -- https://master.php.net/note/delete/114753/spam Del: non-english -- https://master.php.net/note/delete/114753/non-english Del: in docs -- https://master.php.net/note/delete/114753/in+docs Del: other reasons-- https://master.php.net/note/delete/114753 Reject -- https://master.php.net/note/reject/114753 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#199098) next »