Posted by Arjun on Saturday 28th January 2012

Enable GET method in CodeIgniter Framework?

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 will be deleted by the Input class during system initialization to prevent Security Hacks.

To Enable GET Method in CodeIgniter, it is necessary to modify some configuration settings. The uri_protocol setting needs to be changed to PATH_INFO. See the Steps

If you Point the browser with

http://localhost/index.php/welcome/?var1=1&var2=2&var3=3

Output will be something like this

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

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

application/config/config.php
Change the URI Protocol to PATH_INFO

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

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