Welcome Guest, Not a member yet? Register   Sign In
CI 1.7: ORIG_PATH_INFO and URI Class
#1

[eluser]Unknown[/eluser]
This post is related to the fix that was made in CI 1.6.2 (bug (#3191) with ORIG_PATH_INFO URI parsing).

I ran into a special case in one of my projects, where:
- $_SERVER['PATH_INFO'] wasn't available
- $_SERVER['QUERY_STRING'] was available but was always empty
- $_SERVER['ORIG_PATH_INFO'] was available.

In this case, the following branch in URI class is executed (lines 92-98):

Code:
$path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');    

            if (trim($path, '/') != '' && $path != "/".SELF)

            {

                // remove path and script information so we have good URI data

                $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path);

                return;

            }

The problem here is that on the server in question, for some reason, also $_SERVER['SCRIPT_NAME'] == $_SERVER['ORIG_PATH_INFO'], so the str_replace returned an empty string, causing $this->uri_string always to be empty, regardless of the actual path. This of course caused some unwanted effects on the site.

My solution was to revert back to the old code where simply

Code:
$this->uri_string = $path;

in the ORIG_PATH_INFO branch, too.

I realize there must've been some reason for the fix in 1.6.2 and that my case is rather rare (the server is configured in some really weird way) but this is just to let everyone know. Someone might encounter the same problem some day.
#2

[eluser]Nameless One[/eluser]
I encountered this problem in 1.7.1 and bypassed it the same way. I don't think this case is very rare. If I understand the $_SERVER variable correctly, as server without PATH_INFO and with empty QUERY_STRING will always have ORIG_PATH_INFO == SCRIPT_NAME when there's no URI segment that defines an application.

In my case, the URL www.mywebsite.com/section/subsection, which is rewritten to index.php and routed to www.mywebsite.com/controller/action/subsection, doesn't work because both ORIG_PATH_INFO and SCRIPT_NAME will be /section/subsection. However, the URL www.mywebsite.com/admin/section/subsection, which is rewritten to admin.php and routed to www.mywebsite.com/application/controller/action/subsection, works because SCRIPT_NAME is /admin/section/subsection and ORIG_PATH_INFO is /section/subsection. This happens because the application URI segment is part of the base path.

I think the only thing the CI developers need to do is add another if to handle the case when there are no directories in the base path and handle it without the str_replace() call.




Theme © iAndrew 2016 - Forum software by © MyBB