CodeIgniter 访问 $_GET
在开启了 rewrite 的情况下,CI 会 unset 掉 $_GET 超级全局变量,在 config.php 里面,我们可以看到2个关键的设置
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string. The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = "AUTO";
$config['enable_query_strings'] = FALSE;
uri_protocol 设置了 uri 的解析方法,当开启了 rewrite 后,这里为 PATH_INFO,同时会 unset $_GET,我在给网站做支付的时候,因为支付平台那边在用户支付成功后会以 GET 的方式调用通知接口,因此必须读取 $_GET,有两个方法,最简单地,我们可以设置
$config['enable_query_strings'] = TRUE;
但这种方法会对整站产生效果,就是用户依然可以通过 GET 传入 Controller 和 Action 等参数;另一个相对安全点的方法,我们通过 buildin 函数 parse_str 来把 $_SERVER['QUERY_STRING'] 转换成数组
parse_str($this->input->server('QUERY_STRING'), $getParams);
接下来,我们就可以访问 $getParams 来访问 $_GET 了


留言 (3)
ganlan
March 12th 2009 • 17:31
点广告了
小黑米
March 12th 2009 • 22:22
我以前也有遇到这个问题...
但后来是单独把这部分那出来做的...
因为考虑到性能问题 还有就是你的这个问题~
Bun Wong
March 13th 2009 • 09:08
哇!小黑哥哥也用 CI 的呀?