Part of the EllisLab Network
   
1 of 3
1
Default Controller Bug
Posted: 28 February 2007 07:32 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  66
Joined  07-12-2006

I have the exact same ci setup and problem as described in this topic.

His solution of commenting out that code in Router.php did indeed fix the problem. My question is, has this bug been addressed yet? That topic was from way back in April of 06 and the same issue is still occuring in CI 1.5.2. If you could look into this it would be much appreciated.

(this topic explains the problem as well).

Thanks,
Kevin

Profile
 
 
Posted: 28 February 2007 08:40 PM   [ Ignore ]   [ # 1 ]  
Grad Student
Rank
Total Posts:  32
Joined  02-27-2007

Hi,

I believe my problem is related as well.  You can see my problem at:

http://codeigniter.com/forums/viewthread/48101/

I don’t really have a solution yet, but I think I am close.

Regards,

Mediaslave

Profile
 
 
Posted: 28 February 2007 08:55 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  32
Joined  02-27-2007

Hi,

Yep, sure enough commenting out the lines:

/* No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists?*/
$path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');    
if (
$path != '' AND $path != "/".SELF)
{
    
return $path;
}

in

system/libraries/Router.php on Lines 319 - 324

I will look into a final solution.

Regards.

Profile
 
 
Posted: 28 February 2007 09:39 PM   [ Ignore ]   [ # 3 ]  
Grad Student
Rank
Total Posts:  66
Joined  07-12-2006

yea i am just hoping that commenting this out does not affect something else.

Profile
 
 
Posted: 28 February 2007 11:56 PM   [ Ignore ]   [ # 4 ]  
Grad Student
Rank
Total Posts:  32
Joined  02-27-2007

Hey,

Check out this thread.  I have a patch, I just want to know the best way to go about it.

Check it out!

Regards,

Mediaslave

Profile
 
 
Posted: 01 March 2007 10:29 AM   [ Ignore ]   [ # 5 ]  
Grad Student
Rank
Total Posts:  66
Joined  07-12-2006

so using your patch, you can uncomment the code in router.php? how and where is the $_SERVER[’PHP_SELF’] used?

nonetheless, i think this issue needs to be addressed by the codeigniter team because it seams like a legitimate bug. we shouldn’t need to be doing any of these hacks for this subdirectory setup.

thanks

Profile
 
 
Posted: 01 March 2007 11:30 AM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  32
Joined  02-27-2007

Hi,

I can give you the quick patch that works for me let me know how this works for you.  I did not have to uncomment that line, but did have to change the CI_Router class in two places.  I have tested this patch on root, subdirectory and subdomain installations.  All have been successful.  Please let me know your thoughts.

The main problem is that it uses

$path != “/” . SELF

On most setups this works because /index.php doesn’t match both the $_SERVER[‘PATH_INFO’] and/or $_SERVER[‘ORG_PATH_INFO’].  I did not worry about $_SERVER[‘QUERY_STRING’] because it does not compare the $path variable to “/” . SELF.

SOLUTION

Add the code below in the bootstrap file (index.php) just below the user defined $application_folder.

/*
|---------------------------------------------------------------
| PUBLIC ROOT TO BOOTSTRAP DIRECTORY
|---------------------------------------------------------------
|
| If you are doing the default installation in the root directory
| of your domain then you will not have to change this variable.
|
| If you install this boot strap file in any other directory except
| for the root directory (/) then you can specify the path to this
| file.  This is only the directory structure exluding the file name.
|
| If you have the server variable $_SERVER['PHP_SELF'] this variable
| will be auto detected and can be left empty ("").
|
| Example: /PATH/TO/BOOTSTRAP
|
| NO TRAILING SLASH!
|
*/
    
$public_root_path = "";


Then add the following code below the section of code where CI determines the APPPATH constant and right above the DEFINE E_STRICT code:

/**
* Determine the PUBLICROOTTOSELF constant to help with routing.
*/
if(is_dir($public_root_path) && $public_root_path != '/')
{
    define
('PUBLICROOTTOSELF', $public_root_path . '/' . SELF);
}
else
{
    $public_root_path
= '';
    if(isset(
$_SERVER['PHP_SELF']) && dirname($_SERVER['PHP_SELF']) != '/')
    
{
        $public_root_path
= dirname($_SERVER['PHP_SELF']);
    
}
    define
('PUBLICROOTTOSELF', $public_root_path . '/' . SELF);
}

And now onto the Router.php file (system/libraries/Router.php).  Both changes to the code happen in the _get_uri_string() starting around line 288.

Lines 306 and 307 look like:

$path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');    
            if (
$path != '' AND $path != "/".SELF)

change these to:

$path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');    
            if (
$path != '' AND $path != PUBLICROOTTOSELF)

AND

Lines 320 and 321 look like:

$path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');    
            if (
$path != '' AND $path != "/".SELF)

change these to:

$path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');    
            if (
$path != '' AND $path != PUBLICROOTTOSELF)


Now save the files and upload them.  Everything should be fixed.  Well it looks like the forum only allows image uploads so I have provided the zip file on my server.

Download Patch Files

Please let me know.

Regards,

Mediaslave

Profile
 
 
Posted: 01 March 2007 12:42 PM   [ Ignore ]   [ # 7 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6762
Joined  03-23-2006

Hey guys.  I want to help you fix this up and get it into the core.

Are you able to provide me with:

Short description of bug
Files affected
Why is this a bug
Proof of concept code
Proof of concept patch
Will this patch break anything else

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 01 March 2007 01:04 PM   [ Ignore ]   [ # 8 ]  
Grad Student
Rank
Total Posts:  66
Joined  07-12-2006

Sure Derek,

The problem is when you have multiple applications running (one in the root and one in a subdirectory), the default controller for the subdirectory app does not load, unless you explicitly put it in the url. See below for my setup.

domain.com
     admin
          index
.php
         
.htaccess
     system
          application
               admin
               public
     index
.php
    
.htaccess

.htaccess for root

RewriteEngine On
RewriteBase
/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ index.php/$1 [L]

.htaccess for admin

RewriteEngine On
RewriteBase
/admin/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ index.php/$1 [L]

domain.com loads my default controller. however, domain.com/admin/ does not load the default controller for the admin app. domain.com/admin/default_controller/ does work.

i found these two other topics that describe the same problem (please read as well):
http://codeigniter.com/forums/viewthread/46840/
http://codeigniter.com/forums/viewthread/47571/

the first topic suggested commenting out code in Router.php in the _get_uri_string() function starting on line 319. this does fix the problem, but i am not sure what affect this may have on other stuff, so i can not answer your question in regards to if this will break anything else. commenting out this code also worked for mediaslave; however, he came up with another patch. i have not gotten a chance to look into that patch yet. i am sure he will reply to this as well.

thank you for looking into this. will there be a new release when this is fixed? 1.5.3? if not, please post back in here when it is included in 1.5.2 so i can re-download.

Profile
 
 
Posted: 01 March 2007 01:36 PM   [ Ignore ]   [ # 9 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6762
Joined  03-23-2006

thanks ksheurs

What I’m trying to do here is triage bug reports.  Sorry, I’m sure this is glaringly obvious for you, but I’m trying to accelerate my understanding of this and other bugs without needing to go re-read 20 pages of posts wink

Anything you can do to make my life easier will get this bug resolved faster… smile

So it appears that this only manifests if you’re running multiple applications off one CI install.  Is this only a problem if you’re using htaccess files?  Can you explain to me why its breaking?  For example, “CI has a hard-coded path in $file.php and it is isn’t looking in $otherplace”.  That type of thing?

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 01 March 2007 01:45 PM   [ Ignore ]   [ # 10 ]  
Grad Student
Rank
Total Posts:  32
Joined  02-27-2007

Hi Derek,

I am setting up something to help you.  I should post in the next hour.

Thanks for you help in this.

Regards,

Mediaslave

Profile
 
 
Posted: 01 March 2007 01:51 PM   [ Ignore ]   [ # 11 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6762
Joined  03-23-2006

Awesome, thanks both.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 01 March 2007 02:08 PM   [ Ignore ]   [ # 12 ]  
Grad Student
Rank
Total Posts:  32
Joined  02-27-2007

Hi Derek,

Thanks for your response.

You know I am really new to CI so I probably am not the best person to answer:

Will this patch break anything else?

As far as the other questions I will try to provided what I can to answer them to the best of my knowledge:

SHORT DESCRIPTION OF BUG

This bug is happening whenever the installation of CI is in a sub folder and not installed in the root directory.  The problem occurs in the Router.php file (system/libraries/Router.php).  It is comparing the wrong strings. 


FILES AFFECTED WITH PATCH

You can download the zip file here, it only contains the files effected.

ci/index.php
ci/system/libraries/Router.php

WHY IS THIS A BUG

It tries to compare the constant SELF to various $_SERVER variables (PATH_INFO and ORG_PATH_INFO) in the _get_uri_string() starting around line 288 of Router.php.  SELF is constant to compare against due to the subdirectory installation.  What is need to compare is the full path from the public root to self.

PROOF OF CONCEPT CODE

I have unpacked CI 1.5.2 and uploaded it to /bug.  I have an install directory of:

/bug
/bug/index.php
/bug/system

Everything else in the system folder is default.

If you go to the following address they all should load the welcome controller

http://www.jepamedia.com/bug                               <<<<<CI 404
http://www.jepamedia.com/bug/                              <<<<<CI 404
http://www.jepamedia.com/bug/index.php                     <<<<<CI 404
http://www.jepamedia.com/bug/index.php/                    <<<<<Success
http://www.jepamedia.com/bug/index.php/welcome             <<<<<Success
http://www.jepamedia.com/bug/index.php/welcome/index       <<<<<Success

PROOF OF CONCEPT PATCH

I have unpacked CI 1.5.2 and uploaded it to /patched.  I have an install directory of:

/patched
/patched/index.php
/patched/system

Everything else in the system folder is default.

If you go to the following address they all should load the welcome controller

http://www.jepamedia.com/patched                               <<<<<Success
http://www.jepamedia.com/patched/                              <<<<<Success
http://www.jepamedia.com/patched/index.php                     <<<<<Success
http://www.jepamedia.com/patched/index.php/                    <<<<<Success
http://www.jepamedia.com/patched/index.php/welcome             <<<<<Success
http://www.jepamedia.com/patched/index.php/welcome/index       <<<<<Success

PATCHED CODE

Get it here.

Derek please let me know if you need anything else.

Regards,

Mediaslave

Profile
 
 
Posted: 01 March 2007 02:09 PM   [ Ignore ]   [ # 13 ]  
Grad Student
Rank
Total Posts:  32
Joined  02-27-2007

By the way the above installation do not use mod_rewrite.  This does work with mod_rewrite though as well.

Mediaslave

Profile
 
 
Posted: 01 March 2007 02:11 PM   [ Ignore ]   [ # 14 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6762
Joined  03-23-2006

Thanks man,

Give me a bit of time with this ok.

Derek

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 01 March 2007 02:15 PM   [ Ignore ]   [ # 15 ]  
Grad Student
Rank
Total Posts:  66
Joined  07-12-2006

no the problem isn’t only when you are using .htaccess files. if i remove the .htaccess files:

domain.com loads the default controller for the public application
domain.com/index.php loads the default controller for the public application

domain.com/admin/ throws a 404
domain.com/admin/index.php/ says “No input file specified.”
domain.com/admin/index.php/welcome loads the default controller fort he admin app

it seams that i am having all of the same problems as mediaslave, except that i have 2 installations (root and admin) and domain.com/admin/index.php works for him, where for me it throws a “No input file specified.”

the problem seams to be with what is being returned in Router::_get_uri_string().

thats all i got, hopefully mediaslave can be of more assistance.

Profile
 
 
   
1 of 3
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66427 Total Logged-in Users: 37
Total Topics: 84790 Total Anonymous Users: 3
Total Replies: 455010 Total Guests: 234
Total Posts: 539800    
Members ( View Memberlist )
Newest Members:  llogocsaturkeyPeter BryanttherendStudioGeorgiaJZeerfedegheEdgedcenticeRoger_Mx