Codeigniter (v2) 中不允许的关键字符错误消息

发布于 2025-01-05 21:25:26 字数 216 浏览 4 评论 0原文

我最近在我正在构建的自定义 cms 中遇到了此错误 - 当我提交使用多选的表单时会出现此错误 - 任何人都可以建议此错误的最常见原因。

好的 - 我认为这可能是多选数组引起的问题,例如我在表中有一个这样的数组..

hotels[url][]
hotels[text][]
hotels[url][]

$_POST 中不允许这样做吗?

I've recently come across this error within a custom cms i'm building - this error appears when I submit a form that uses a multiselect - can anyone suggest the most common reasons for this error.

ok - i think it might be the multi-select arrays causing the problem, eg I have an array like this within a table..

hotels[url][]
hotels[text][]
hotels[url][]

Would this not be allowed in the $_POST?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

极致的悲 2025-01-12 21:25:26

如果您查看 application/config 文件夹内的 config.php 文件,您会发现这一行:

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

It's a regex contains codeigniter alloweds 白名单字符。如果查询字符串中有其他内容,您将收到该错误。

If you look in your config.php file inside the application/config folder you'll find this line:

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

It's a regex containing whitelisted characters that codeigniter allows. If there is anything else in the querystring you will get that error.

幻想少年梦 2025-01-12 21:25:26

您可能使用 GET 而不是 POST 提交表单。多选通常使用数组表示法 (myarray[]),这些字符通常是 CodeIgniter 在 URL 中不允许使用的字符。

如果您确定使用的是 POST,那么我建议您检查两件事:

  1. 如果您使用的是 CodeIgniter 的 CSRF 保护,请确保您正在使用表单提交有效的令牌。您可以通过禁用 CSRF 保护并尝试提交表单来测试这是否是问题。 CSRF 保护通常通过 $config['csrf_protection'] 变量在 config.php 文件中启用。有关 CodeIgniter 的 CSRF 保护的更多信息,请访问 这里
  2. 仔细检查您用于提交表单的 URL,以确保它不包含 application/config/config.php 中 $config['permissed_uri_characters'] 中不允许的任何字符。

It could be you're submitting your form with GET instead of POST. Multi-selects usually use array notation (myarray[]) which are characters that are not usually allowed by CodeIgniter in the URL.

If you are sure you're using POST then I would suggest checking two things:

  1. Make sure that if you're using CodeIgniter's CSRF protection that you are submitting a valid token with the form. You can test whether this is the problem by disabling CSRF protection and trying to submit the form. The CSRF protection is usually enabled in your config.php file via the $config['csrf_protection'] variable. More info on CodeIgniter's CSRF protection can be found here.
  2. Double check the URL you're using to submit the form to make sure it doesn't have any characters that aren't permitted in your $config['permitted_uri_characters'] in application/config/config.php.
旧故 2025-01-12 21:25:26

从输入名称中删除逗号。
例如:name['type'] 是错误的。
应该是名称[类型]

remove commas from your input names.
Eg: name['type'] is wrong.
It should be name[type]

她如夕阳 2025-01-12 21:25:26

if (!preg_match(“/^[a-z0-9:_/-]+$|/i”, $str))

我添加 |上例中的(管道)字符

if ( ! preg_match(“/^[a-z0-9:_/-]+$|/i”, $str))

I add | (pipe) character on the example above

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文