Enabling $_GET in codeigniter Enabling $_GET in codeigniter codeigniter codeigniter

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');


From the CodeIgniter's manual about security:

GET, POST, and COOKIE Data

GET data is simply disallowed by CodeIgniter since the system utilizes URI segments rather than traditional URL query strings (unless you have the query string option enabled in your config file). The global GET array is unset by the Input class during system initialization.

Read through this forum entry for possible solutions (gets interesting from halfway down page 1).


I don't have enough reputation to comment, but Phil Sturgeon's answer above is the way to go if switching to Codeigniter Reactor is easy for you.

You can access the query string by using $_GET or $this->input->get() without having needing the MY_Input override or even altering the config.php file.