- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在努力寻找一种解决方案来继续使用 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 inphp.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/
我已经在我的 ini 文件中设置了 suhosin.perdir = 'p'。我现在想在每个文件夹的基础上更改 suhosin ini 设置。 以下所有工作(在所需文件夹内运行 phpinfo() 显
我的/var/log/messages 中有很多 suhosin 错误 Dec 22 06:28:12 server suhosin[4637]: ALERT - configured request
我用的是suhosin。我收到以下警报。 ALERT-SIMULATION - tried to register forbidden variable '_REQUEST' through GET
suhosin 正在过滤一个重要的 GET 参数。 当以下不起作用时,如何覆盖 suhosin? public_html/php.ini : [suhosin] suhosin.get.max_val
我对数据库非常陌生。我正在设计一个网站,很高兴我能处理错误日志中的错误。最近我的错误日志不断记录“PHP警告:...无法加载...suhosin.so” 显然,每当我查询某些内容时,就会创建一个新条目
你好,我有一个简单的 php 脚本,它更像是一个只有很少 php 行的 html 文件。然而它会在日志中产生大量错误,每一行都像这样: PHP Warning: PHP Startup: Unabl
我一直想知道 Suhosin Patch 和 Extension 之间的区别? 例如,我应该使用 PHP 5.2.17 和 Xcache 1.3.1 和 Zend Optimizer 3.3.0.a
我刚刚注意到我的主机开始使用 Suhosin Hardening,我对此不太熟悉并且我的应用程序存在重大问题,主要是在 session 中。 session 现在以下列格式存储: _EzyqHpPJq
Suhosin 似乎修补并扩展了 PHP 核心,作为保护用户免受核心缺陷影响的一种手段。似乎也有一些聪明人正在使用这个系统。既然它看起来是一件好事,我很好奇为什么它不是 PHP 核心的一部分。有人知道
我在 ubuntu12.04 上运行 PHP5.6 作为 apache 2.4 模块Suhosin 从源安装 Suhosin 已启用,我可以在 phpinfo() 函数输出中看到它。我在 suhosi
出于某种原因,设置后我无法在任何页面上从我的 CakePHP 应用程序读取任何 cookie,唯一返回的是乱码文本。 我的代码就这么简单: $this->Cookie->write('Region',
在回答这个问题之前,我会说我不是 Web 开发人员,而且我在该领域的知识也不多。我是一名企业主,我的客户在其上购买产品的网站数量较少。几分钟前我注意到了这组查询,对于我这个外行人来说,它们看起来非常可
我有一个使用 CodeIgniter 框架用 PHP5 编写的应用程序。 我让它在 Windows(使用 Xampp)和 Ubuntu(使用标准 Apache、PHP、MySQL 堆栈)上运行。 我有
我想将我的系统从 PHP 5.6.17 移植到 7.0.2。作为操作系统,我们使用 CentOS Linux release 7.2.1511。 我发现我的系统没有兼容的 suhosin (secur
我有一个运行 PHP 脚本的 Apache 服务器,该脚本通过具有多个字段的 POST 请求接收数据。其中一个字段可能很长,当它达到 512 kB 到 1 MB 之间时,它会被丢弃,即。 e.收到的
我有一个 PHP 脚本,它需要随机化一个具有一致结果的数组,因此它可以向用户显示前几项,然后他们可以根据需要从相同的随机集合中提取更多结果。 我目前使用的是这个(我相信基于 Fisher Yates
我正在努力寻找一种解决方案来继续使用 Suhosin 补丁并使其适用于 UTF-8 表单提交。这是我做的非常简单的测试: 使用字符串 iñtërnâtiônàlizætiøn
我目前正在开发一个最终会在商业上可用的 PHP CMF,我想使用特征。然而问题在于,trait 是 PHP 5.4 的特性,而且很明显流行的 Suhosin 安全补丁与 PHP 5.4 不兼容。 所以
我是一名优秀的程序员,十分优秀!