作者 : Bun Wong
日期 : 2009年03月12日
标签 : PHP CodeIgniter
浏览 : 1066 次
评论 : 3 个
http://www.hdwong.com/article/27/

CodeIgniter 访问 $_GET

技术交流 @ 2009年03月12日 收藏&分享

在开启了 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)

  • #1. ganlan

    2009年03月12日

    点广告了

  • #2. 小黑米

    2009年03月12日

    我以前也有遇到这个问题...
    但后来是单独把这部分那出来做的...
    因为考虑到性能问题 还有就是你的这个问题~

  • #3. Bun Wong

    2009年03月13日

    哇!小黑哥哥也用 CI 的呀?

* 昵称:

* 评论:

* 验证码: (请输入下图的 4 位数字)

Captcha看不请, 换一张

© 2011 Bun Wong

本博客基于 Bun PHP Framework 构建 • 粤ICP备07036370号