Enabling $_GET in codeigniter

Add the following library to your application libraries. It overrides the behaviour of the default Input library of clearing the $_GET array. It allows for a mixture of URI segments and query string.

application/libraries/MY_Input.php

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

Its also necessary to modify some configuration settings. The uri_protocol setting needs to be changed to PATH_INFO and the ‘?’ character needs to be added to the list of allowed characters in the URI.

application/config/config.php

$config['uri_protocol'] = "PATH_INFO";
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?';

It is then possible to access values passed in through the query string.

$this->input->get('x');

Leave a Comment