PHP $_POST 数组变量被截断 [英] PHP $_POST array variables are truncated

查看:21
本文介绍了PHP $_POST 数组变量被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 PHP 5.3.8 和 Apache 2.0.我也在使用 Symfony 2 但这不是脚本失败的地方.我有一个带有数组变量的表单:

I am using PHP 5.3.8 with Apache 2.0. I am also using Symfony 2 but that's not where the script is failing. I have a form with array variables:

<form action="/app_dev.php/admin/position/create" method="post">
  <input type="text" id="po_name" name="po[name]" required="required" maxlength="50">
  <input type="text" id="po_role" name="po[role]" required="required" maxlength="20">
</form>

直接在 app_dev.php 文件中(从问题中排除 Symfony)我这样做:

Directly in the app_dev.php file (to rule out Symfony from the problem) I do:

echo file_get_contents("php://input"); // outputs: po%5Bname%5D=Developer&po%5Brole%5D=ROLE_USER
var_dump($_POST); // outputs: array(1) { ["po"]=> array(1) { ["name"]=> string(9) "Developer" } }
die();

基本上它只保留数组中的第一个变量.如果我将变量的名称从 po[role] 更改为 ba[role] 然后 $_POST 输出:

Basically it keeps only the first variable in the array. If I change the name of the variable from po[role] to ba[role] then $_POST outputs:

array(1) {
  ["po"]=> array(1) { ["name"]=> string(9) "Developer" },
  ["ba"]=> array(1) { ["role"]=> string(9) "ROLE_USER" }
}

我发现可能导致此问题的典型问题是由于以下 php.ini 配置,我还给您我的值:

Typical problems I have found that can cause this issue are due to the following php.ini configuration, I also give you what are my values:

max_execution_time = 30
max_input_time = 60 
max_input_nesting_level = 64
max_input_vars = 1000
post_max_size = 8M
upload_max_filesize = 2M
memory_limit = 128M

这些值似乎合理,我认为不会导致问题,但不能 100% 确定.

These values seems reasonable and I think don't cause the problem, but cannot be 100% sure.

没有安装 suhosin,因为我读过它也会导致类似的问题.

I do not have suhosin installed as I've read it can cause similar problems too.

也类似于这个问题 但给出的解决方案需要我重写 HttpFoundation Symfony 组件.

It is also similar to this problem but the solution given would require me to rewrite the HttpFoundation Symfony component.

此外,我不想重写没有和数组的表单变量(例如 po[name] 到 po_name),因为表单是由 Symfony 自动生成的,这似乎是一个基本的PHP 应该能够处理的功能.

Also I don't want to have to rewrite the form variable without and array (e.g. po[name] to po_name) as the form are automatically generated by Symfony and this seems to be a basic feature that PHP should be able to handle.

有人知道这个问题吗?

PS:这类似于此处中描述的问题.此外,问题发生在相同版本的 Suse (SUSE Linux Enterprise Server 11) 上.

PS: this is similar to the problem described in here. Plus the problem happens on the same version of Suse (SUSE Linux Enterprise Server 11 ).

推荐答案

我们最终决定将我们的 PHP 版本更新到更新的版本 (5.3.15),现在它可以正常工作了.所以这肯定是这个 5.3.8 的问题,至少是我们拥有的版本.

We finally decided to update our version of PHP to a more recent version (5.3.15) and it works fine now. So this was for sure a problem with this 5.3.8, at least the version we had.

这篇关于PHP $_POST 数组变量被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆