Welcome Guest, Not a member yet? Register   Sign In
Scripts not working when uri_protocol is set to PATH_INFO
#1

[eluser]marcusl[/eluser]
Hello everyone. I've been working on a project using CodeIgniter. To test my app locally, I've been using Xampp, which works great. However, once I uploaded my app onto a web server, it ceased to work. When I type in:

http://test.com/api/index.php/script

I would get CodeIgniter's welcome page, and not script.php, which is what I would've expected.

After some experimenting, I noticed this line in my config.php:

$config['uri_protocol'] = "PATH_INFO";

Just as a test, I changed this setting from PATH_INFO to AUTO, and the scripts began to work on the live site. The trouble is, I have scripts where I pass on parameters using this method:

http://test.com/api/index.php/script?limit=5

When I make the above call, the server returns a 404 error. Note that the 404 code isn't returned from my php script, but rather from the server. Again, if I strip out the variable and go:

http://test.com/api/index.php/script

Then the script runs fine again.

Basically, I need to set uri_protocol to PATH_INFO, but I'm not sure what server settings need to be changed in order to get this to work, because again, right now, when I set it to PATH_INFO, nothing works.

Thanks guys.
#2

[eluser]mi6crazyheart[/eluser]
Hey, i think problem is in u'r url( http://test.com/api/index.php/script ) which u'd given. According to CI's url convention it should be something like this...

Code:
example.com/index.php/products/shoes/sandals/123
from above "example.com/index.php" portion is default and

product: controller file
shoes: function name
sandals & 123 both are two parameters which are sending to the controller function(shoes)...

For more details: http://ellislab.com/codeigniter/user-gui...llers.html
#3

[eluser]marcusl[/eluser]
Thanks for the reply. I'm not sure if that's the issue, though, because as I've mentioned, the same url does work when I'm running it off localhost. I've also had this app up on another server before, and there were no issues there. I'm confident that I just need to be able to change the settings to this:

$config['uri_protocol'] = "PATH_INFO";

Instead of:

$config['uri_protocol'] = "AUTO";

Thanks guys.
#4

[eluser]mi6crazyheart[/eluser]
Have u enable u'r Query Strings value... which u can do this by :
Code:
$config['enable_query_strings'] = TRUE;

For more info: http://ellislab.com/codeigniter/user-gui.../urls.html
#5

[eluser]WanWizard[/eluser]
If the server returns 404 errors when you slap a query string on, you should check your rewrite rules. As the request never reaches CI, you can not fix it there.

The "enable_query_string" config value is to enable routing via the query string, not to allow get values to survive. For that you have to extend the Input library:
Code:
class MY_Input extends CI_Input
{
    function MY_Input()
    {
        parent:CI_Input();
    }

    function _sanitize_globals()
    {
        $this->allow_get_array = TRUE;
        parent::_sanitize_globals();
    }

}
#6

[eluser]pbreit[/eluser]
So would getting rid of this code in /system/core/Input.php enable querystring support? I obviously don't want to mess with core but am just wondering if it's this simple. Is there any downside?

[code] if ($this->_allow_get_array == FALSE)
{
$_GET = array();
}{/code]
#7

[eluser]marcusl[/eluser]
Thanks for the replies.

Inside config.php, I've changed enable_query_strings to TRUE. The uri_protocol is changed from AUTO back to PATH_INFO. Just as a quick test, inside Input.php, I've replaced:

if ($this->allow_get_array == FALSE)
{
$_GET = array();
}
else
{
$_GET = $this->_clean_input_data($_GET);
}

With simply:

$_GET = $this->_clean_input_data($_GET);

Unfortnately, that still didn't work. If I go:

http://test.com/api/index.php/test?limit=5

All I get is CodeIgniter's welcome page. If I go:

http://test.com/api/index.php/test

Then it works fine.

Thank.
#8

[eluser]pbreit[/eluser]
I think you want to be using WanWizard's code and with *NO* changes to the default configs: uri_protocol, enable_query_strings, permitted_uri_chars.




Theme © iAndrew 2016 - Forum software by © MyBB