CodeIgniter POST 变量
我在 CodeIgniter 过滤掉包含带重音符号的 POST 变量时遇到问题。
这是我的 HTML 页面:
<!DOCTYPE html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>
<body>
<form action="/test" method="post" accept-charset="utf-8">
<input type="text" name="name" value="" />
<input type="submit" name="submit" value="Submit" />
<form>
</body>
</html>
这是我的“/test”CodeIgniter 控制器的索引函数:
public function index {
echo '<pre>';
print_r($_POST);
die();
}
...输入“我的名字”的名称后,我得到:
Array
(
[name] => my name
[submit] => Submit
)
...但是输入“我的名字”的名称,变量作为空传递:
Array
(
[name] =>
[submit] => Submit
)
如果我将相同的表单发布到独立的 PHP 脚本,它工作正常。我在配置中看不到导致此问题的任何明显内容。有人可以帮忙吗?
I've got a problem with CodeIgniter filtering out POST variables containing characters with accents.
Here's my HTML page:
<!DOCTYPE html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>
<body>
<form action="/test" method="post" accept-charset="utf-8">
<input type="text" name="name" value="" />
<input type="submit" name="submit" value="Submit" />
<form>
</body>
</html>
Here's the index function of my '/test' CodeIgniter controller:
public function index {
echo '<pre>';
print_r($_POST);
die();
}
...With the name entered as to 'my name' I get this:
Array
(
[name] => my name
[submit] => Submit
)
...But with the name entered as 'my namé', the variable gets passed as empty:
Array
(
[name] =>
[submit] => Submit
)
If I post the same form to a standalone PHP script it works fine. I can't see anything obvious in the config that's causing this. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 config.php 中,将其更改
为其他内容...基本上,如果将其设置为
UTF-8
CI 默认情况下会通过过滤器运行所有内容来检查/转换应用程序是否需要 UTF -8,而 iconv() 的实现是罪魁祸首...请参阅此线程以获取更多信息 https://github.com/EllisLab/CodeIgniter/issues/261In config.php, change this -
to something else... basically what happens is if it's set to
UTF-8
CI by default runs everything through a filter to check/convert if the app is expecting UTF-8, and the implementation of iconv() is the culprit... see this thread for more info https://github.com/EllisLab/CodeIgniter/issues/261这是一个 MAMP 特定的问题,实际上是这个问题的重复,它提供了解决方案: $_POST utf-8 字符为空
It was a MAMP-specific issue, and effectively a duplicate of this question, which provides solutions: $_POST empty on utf-8 characters