views:

1114

answers:

3

I've been trying to figure out how to enable $_GET in CI.

It appears the framework deliberately destroys the $_GET array, and that enabling it requires serious tinkering with the core classes. can anyone say why this is, and how to overcome it?

mind you, i'm looking to keep URI parsing and routing the way they are, just simply have the $_GET available as well.

+3  A: 

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).

Gordon
Whoever downvoted this could at least leave a comment explaining why. The answer is correct and provides alternatives in the given link.
Gordon
It wasn't me :-S
Stephen Curran
+6  A: 

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');
Stephen Curran
A: 

Read my stackoverflow answer also.

Bretticus