TAG | codeigniter
This is in response to an earlier post about making GET work in Codeigniter
Basically I need GET in CodeIgniter, but I didn’t really want to apply the patch that I found on the Internet. I wanted a very simple solution, and I like the hook idea a lot better, so I followed the pattern from the second link, but it was by no means complete. Here is how I did it.
Enable hooks in system/application/config/config.php
$config['enable_hooks'] = TRUE;
Added a “pre_system” hook array into system/application/config/hooks.php
$hook['pre_system'] = array(
'class' => '',
'function' => 'allow_query_string',
'filename' => 'allow_query_string.php',
'filepath' => 'hooks',
'params' => array()
);
Added a hook file system/application/hooks/allow_query_string.php
with the following contents
function allow_query_string() {
if (strlen($_SERVER['QUERY_STRING']) > 0) {
$temp = @array();
parse_str($_SERVER['QUERY_STRING'], $temp);
if (array_key_exists('token', $temp)) {
$_POST['token'] = $temp['token'];
$_SERVER['QUERY_STRING'] = "";
$_SERVER['REDIRECT_QUERY_STRING'] = "";
$_GET = @array();
$loc = strpos($_SERVER['REQUEST_URI'], '?');
if ($loc > -1) {
$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $loc);
}
}
}
}
notes: your get parameters will appear in the $_POST array, it is very important that you keep that input safe by xss_clean’ing it
$this->input->xss_clean($_POST['token']);
In the allow_query_string.php you will notice that I am specific to ONLY allow the GET arg ‘token’ because that is all that I need right now. Later I may need to modify that, or eliminate it all together.
Enable GET for CodeIgniter
I am not sure how much I love the fact that CI thinks that it is ok to ignore GET’s… With OAuth, we are forced to have a GET come in upon authentication. So, this is really frustrating. I don’t know if I want to patch my code, I kind of like having stock CI install. But, maybe it is irrelevant because I am modifying application code which is inside the CI directory structure anyway, but it is a principle thing. Why should I modify CI just to get what PHP gave me in the first place ARRGGGG.
http://codeigniter.com/forums/viewthread/46809/
http://snipplr.com/view/5967/allow-get-in-codeigniter/

