【问题标题】:CodeIgniter $this->input->get() not workingCodeIgniter $this->input->get() 不工作
【发布时间】:2012-12-26 22:13:23
【问题描述】:

我不确定为什么这不起作用。我在配置文件中有 allow_get_array = TRUE 。这就是我想做的事情..

这是用户将从他们的电子邮件中单击的链接

http://www.site.com/confirm?code=f8c53b1578f7c05471d087f18b343af0c3a638

confirm.php 控制器:

$code = $this->input->get('code');

也试过

$code = $this->input->get('code', TRUE);

有什么想法吗?

【问题讨论】:

标签: php codeigniter


【解决方案1】:

在您的config.php 中更改以下内容:

$config['uri_protocol'] = 'AUTO';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['enable_query_strings'] = FALSE;

收件人:

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

您可以更改 URI 以使用像 http://www.site.com/confirm/code/f8c53b1578f7c05471d087f18b343af0c3a638 这样的段,而不是弄乱查询字符串。要访问代码段,您将使用$this->uri->segment(3);。我个人更喜欢这种方式来使用查询字符串。见URI Class

【讨论】:

  • @KraigBalla 看看我更新的答案,当我使用REQUEST_URI 而不是AUTO 时,我似乎总是有更好的运气,我还添加了一个关于如何解决这个问题的快速建议使用 URI 段。
  • 使用这种方法,您可能会将应用程序置于风险之中,因为您违反了路由规则。
【解决方案2】:

使用这个:

$code = isset($_REQUEST['code']) ? $_REQUEST['code'] : NULL;

编辑:

在 PHP >=7.0 中,您可以这样做:

$code = $_REQUEST['code'] ?? NULL;

【讨论】:

    【解决方案3】:

    我这样做了,它无需更改配置文件即可工作:

    //put some vars back into $_GET.
    parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);
    
    // grab values as you would from an ordinary $_GET superglobal array associative index.
    $code = $_GET['code']; 
    

    【讨论】:

    • @CollinsAbitekaniza,但它是 codeigniter 方法,它不会清除 XSS
    【解决方案4】:

    你可以试试吗

    http://www.site.com/confirm/?code=f8c53b1578f7c05471d087f18b343af0c3a638
    

    而不是

    http://www.site.com/confirm?code=f8c53b1578f7c05471d087f18b343af0c3a638
    

    没有任何配置,否则请编辑

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-29
      • 1970-01-01
      • 2012-09-04
      • 2021-05-26
      • 1970-01-01
      • 1970-01-01
      • 2013-08-01
      相关资源
      最近更新 更多