CodeIgniter POST 变量

发布于 2024-12-11 07:08:22 字数 927 浏览 0 评论 0原文

我在 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 技术交流群。

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

发布评论

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

评论(2

橪书 2024-12-18 07:08:22

在 config.php 中,将其更改

/*
|--------------------------------------------------------------------------
| Default Character Set
|--------------------------------------------------------------------------
|
| This determines which character set is used by default in various methods
| that require a character set to be provided.
|
| See http://php.net/htmlspecialchars for a list of supported charsets.
|
*/
$config['charset'] = 'UTF-8';

为其他内容...基本上,如果将其设置为 UTF-8 CI 默认情况下会通过过滤器运行所有内容来检查/转换应用程序是否需要 UTF -8,而 iconv() 的实现是罪魁祸首...请参阅此线程以获取更多信息 https://github.com/EllisLab/CodeIgniter/issues/261

In config.php, change this -

/*
|--------------------------------------------------------------------------
| Default Character Set
|--------------------------------------------------------------------------
|
| This determines which character set is used by default in various methods
| that require a character set to be provided.
|
| See http://php.net/htmlspecialchars for a list of supported charsets.
|
*/
$config['charset'] = 'UTF-8';

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

爱人如己 2024-12-18 07:08:22

这是一个 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

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