【问题标题】:How to allow double quotes (quoation marks) in CodeIgniter URLs如何在 CodeIgniter URL 中允许双引号(引号)
【发布时间】:2014-03-12 22:24:02
【问题描述】:

CodeIgniter 新手,但我尝试了几种方法:

Remove Characters from URL with htaccess/ URL array codeigniter/ CodeIgniter Disallowed Key Characters

当使用包含双引号的 URL 时,我不断收到相同的错误:

Disallowed Key Characters.

请有人告诉我我做错了什么。起初这似乎很简单,但显然我不明白。

【问题讨论】:

  • 您为什么要这样做?这是一个安全漏洞。无论如何 urlencode 可能会派上用场:php.net/urlencode
  • 这是一个拥有大量流量的电子商务网站,其流量来源之一 - Google 购物 - 正在发送一长串附加到我们传统 URL 的变量,我假设这是某种形式的分析跟踪由以前的开发人员设置。

标签: php .htaccess codeigniter


【解决方案1】:

打开 CI 目录中的 config 文件夹,查找以下行:

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

如果要使用双引号,请在此处添加。

接下来转到codeigniter->core->input.php

找到:_clean_input_keys($str) function

附加这一行:exit('Disallowed Key Characters.'.$str);

现在您应该看到导致错误的行并相应地修复它。

【讨论】:

  • 我认为使用 /application/code/MY_Input.php 扩展输入类比编辑 CI 核心更好
  • 我无法通过上述方法解决我的问题,但仍然感谢 Edward。
【解决方案2】:

这似乎对我有用。在咨询了几个来源后,我意识到有多种方法可以解决这个问题。我在 html/system/core/Input.php 中修改了此部分以匹配以下内容。我插入了一个 PHP 函数,它用 ' 替换 URL 字符串的实例。完成了这项工作。

 /**
  * Clean Keys
  *
  * This is a helper function. To prevent malicious users
  * from trying to exploit keys we make sure that keys are
  * only named with alpha-numeric text and a few other items.
  *
  * @access private
  * @param  string
  * @return string
  */
  function _clean_input_keys($str)
  {
     $str = str_replace('"','',$str);
    if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
    {
      exit('Disallowed Key Characters...');
    }

    // Clean UTF-8 if supported
    if (UTF8_ENABLED === TRUE)
    {
      $str = $this->uni->clean_string($str);
    }

    return $str;
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 2017-10-06
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多