gpt4 book ai didi

PHP 5.3、Suhosin 和 UTF-8

转载 作者:搜寻专家 更新时间:2023-10-31 22:14:52 24 4
gpt4 key购买 nike

我正在努力寻找一种解决方案来继续使用 Suhosin 补丁并使其适用于 UTF-8 表单提交。这是我做的非常简单的测试:

<?php var_dump($_POST); ?>
<form method="post">
<input name="test" type="text"/>
<input type="submit" />
</form>

使用字符串 iñtërnâtiônàlizætiøn。显然,我首先在服务器上启用了 utf-8 header 并将 Php default_charset 设置为 utf-8 以及我启用了 mb* 覆盖。一旦我禁用 Suhosin 补丁并重新提交表单,一切都会正常进行。

更新

为了确定,我做了更多测试:

$test = $_POST['test'];

var_dump(mb_detect_encoding($test, "UTF-8", true));

// Returns true if $string is valid UTF-8 and false otherwise.
function is_utf8($string) {

// From http://w3.org/International/questions/qa-forms-utf-8.html
return preg_match('%^(?:
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*$%xs', $string);

} // function is_utf8
var_dump(is_utf8($test));

并且两个测试都在启用 Suhosin 补丁的情况下返回 false,否则返回 true。问题是:这是一个错误还是预期的行为? Suhosin 补丁是否有一个配置参数可以对多字节字符串进行一些神奇的处理?

目前我看到的唯一选择是禁用补丁,除非有聪明的头脑给出正确的建议。

更新 2

GET 字符串不会被破坏并正确显示在浏览器中。目前只有 POST 可以。

最佳答案

通过 Google 搜索,我找到了 http://algorytmy.pl/doc/php/ref.mbstring.php其中提到

Beginning with PHP 4.3.3, if enctype for HTML form is set to multipart/form-data and mbstring.encoding_translation is set to On in php.ini the POST'ed variables and the names of uploaded files will be converted to the internal character encoding as well. However, the conversion isn't applied to the query keys.

这对我来说意义不大,但它确实提到了 POST 变量,这似乎是问题的症结所在。

我发现,如果我在我的 Apache 虚拟主机中设置它,我可以重现您的问题:

php_admin_value mbstring.language       "Neutral"
php_admin_value mbstring.encoding_translation "On"
php_admin_value mbstring.http_input "UTF-8"
php_admin_value mbstring.http_output "UTF-8"
php_admin_value mbstring.detect_order "auto"
php_admin_value mbstring.substitute_character "none"
php_admin_value mbstring.internal_encoding "UTF-8"
php_admin_value mbstring.func_overload "7"
php_admin_value default_charset "UTF-8"

作为引用,这是我用来重现问题的 php 测试页面:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<pre><?php echo $_POST['test'];?></pre>
<form method="post">
<input name="test" type="text"/>
<input type="submit" />
</form>
Test string to use: iñtërnâtiônàlizætiøn
</body>
</html>

我尝试注释掉以下 mbstring 设置(或将其关闭):

; Disable HTTP Input conversion (PHP 4.3.0 or higher)
mbstring.encoding_translation = Off

这似乎解决了这个问题,尽管它对我来说意义不大,因为内部字符编码 utf-8??

我注意到的另一个奇怪之处是,如果我直接在 php.ini(而不是 Apache 虚拟主机)中设置这些 mbstring 值,我将无法重现该问题使用 encoding_translation 所以它似乎只有在使用 php_admin_value 时才有问题?

关于PHP 5.3、Suhosin 和 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7711537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com