Changed URI auto-detection to try PATH_INFO first
(thanks to @sourcejedi, PR #1326)
Up until PHP 5.2.4 (which is our new lowest requirement),
there was a bug related to PATH_INFO which made REQUEST_URI
a more reliable choice. This is now no longer the case,
see https://bugs.php.net/bug.php?id=31892 for more details.
Also removed ORIG_PATH_INFO from the suggested alternatives
for uri_protocol in application/config/config.php as it will
not exist in most of PHP's recent versions and is pointless
when you can use PATH_INFO anyway.
diff --git a/application/config/config.php b/application/config/config.php
index 6867cee..0562953 100644
--- a/application/config/config.php
+++ b/application/config/config.php
@@ -64,10 +64,9 @@
|
| 'AUTO' Default - auto detects
| 'CLI' or 'argv' Uses $_SERVER['argv'] (for php-cli only)
-| 'REQUEST_URI' Uses $_SERVER['REQUEST_URI']
| 'PATH_INFO' Uses $_SERVER['PATH_INFO']
+| 'REQUEST_URI' Uses $_SERVER['REQUEST_URI']
| 'QUERY_STRING' Uses $_SERVER['QUERY_STRING']
-| 'ORIG_PATH_INFO' Uses $_SERVER['ORIG_PATH_INFO']
|
*/
$config['uri_protocol'] = 'AUTO';
diff --git a/system/core/URI.php b/system/core/URI.php
index 3b7718f..309c776 100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -102,23 +102,21 @@
return;
}
- // Let's try the REQUEST_URI first, this will work in most situations
+ // Is there a PATH_INFO variable? This should be the easiest solution.
+ if (isset($_SERVER['PATH_INFO']))
+ {
+ $this->_set_uri_string($_SERVER['PATH_INFO']);
+ return;
+ }
+
+ // Let's try REQUEST_URI then, this will work in most situations
if (($uri = $this->_parse_request_uri()) !== '')
{
$this->_set_uri_string($uri);
return;
}
- // Is there a PATH_INFO variable?
- // Note: some servers seem to have trouble with getenv() so we'll test it two ways
- $uri = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
- if (trim($uri, '/') !== '' && $uri !== '/'.SELF)
- {
- $this->_set_uri_string($uri);
- return;
- }
-
- // No PATH_INFO?... What about QUERY_STRING?
+ // No REQUEST_URI either?... What about QUERY_STRING?
if (($uri = $this->_parse_query_string()) !== '')
{
$this->_set_uri_string($uri);
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index e0b8c75..a6494e3 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -236,6 +236,7 @@
- Renamed internal method ``_detect_uri()`` to ``_parse_request_uri()``.
- Changed ``_parse_request_uri()`` to accept absolute URIs for compatibility with HTTP/1.1 as per `RFC2616 <http://www.ietf.org/rfc/rfc2616.txt>`.
- Added protected method ``_parse_query_string()`` to URI paths in the the **QUERY_STRING** value, like ``_parse_request_uri()`` does.
+ - Changed ``_fetch_uri_string()`` to try the **PATH_INFO** variable first when auto-detecting.
- Removed ``CI_CORE`` boolean constant from *CodeIgniter.php* (no longer Reactor and Core versions).
- :doc:`Loader Library <libraries/loader>` changes include:
- Added method ``get_vars()`` to the Loader to retrieve all variables loaded with ``$this->load->vars()``.