【问题标题】:$_GET does not work in Codeigniter 2.1.3 [duplicate]$_GET 在 Codeigniter 2.1.3 中不起作用 [重复]
【发布时间】:2013-04-05 00:35:45
【问题描述】:

我想从类似于 http://localhost/project/?ref=6 的 URI 中获取 ref 值 现在我知道$_GET['ref'] 在codeigniter 中不起作用。我尝试通过设置$config['allow_get_array'] = TRUE; 来启用它,但它不起作用。

我在某处读到了关于使用$this->input->get('ref') 但没有运气。在使用它之前,我确实在 config.php 中加载了input 库。

注意:我想在模型中访问这个值

在 config.php 中添加

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

并评论了现有的 $config['uri_protocol'] = 'REQUEST_URI';$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

控制器代码是:

parse_str($_SERVER['QUERY_STRING'], $_GET);
        $ref = $this->security->xss_clean($_GET['ref']);
        log_message('info','>>>>>>>>>>>>>>>>>>enter email_invites method::'.$ref);

但我仍然没有得到任何价值,而且不知何故我没有看到任何日志消息。

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    此行将解析 URL 并使用 URL 的参数填充 $_GET 数组:

    parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);
    

    然后可以像通常访问数组一样访问它,例如:

    $ref = $_GET['ref'];
    

    你的配置——application/config/config.php——应该设置如下:

    $config['uri_protocol'] = "PATH_INFO";
    

    【讨论】:

    • 不走运。另外,我现在没有看到我的日志消息。
    • $_SERVER['REQUEST_URI']$_GETparse_str(... 行之后的值是多少?
    • 请不要重复答案。而是以评论或重复关闭投票的形式链接已经有答案的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 2014-07-17
    • 1970-01-01
    • 2016-12-24
    相关资源
    最近更新 更多