问题描述
我有一个自定义的内容管理系统 (CMS),可以在我的开发箱 (Ubuntu/PHP5+/MySQL5+) 上完美运行.
I have a custom Content Management System (CMS) I've built that works perfectly on my dev box (Ubuntu/PHP5+/MySQL5+).
我刚刚将它移到我客户的生产框,现在所有表单提交都显示为空的 $_POST 数组.
I just moved it up to the production box for my client and now all form submissions are showing up as empty $_POST arrays.
我发现了一个技巧来验证数据实际上是使用 file_get_contents('php://input');
传递的,并且数据在那里显示良好 -- $_POST
/$_REQUEST
数组总是空的.
I found a trick to verify the data is actually being passed using file_get_contents('php://input');
and the data is showing up fine there -- the $_POST
/$_REQUEST
arrays are always empty.
我还通过 firebug 验证了内容类型标头是否正确(application/x-www-form-urlencoded; charset=utf-8
).
I've also verified the content-type headers are correct as well via firebug (application/x-www-form-urlencoded; charset=utf-8
).
无论表单是通过 AJAX 提交还是常规表单提交,都会发生此问题.
This issue is happening regardless of whether a form is submitting via AJAX or a regular form submit.
非常感谢任何帮助!
推荐答案
当使用 JSON 内容类型时,$_POST
数组不会填充(我相信只有多部分表单)
When using JSON content-type the $_POST
array will not populate (only with multi-part forms I believe)
以下是我纠正问题的方法:
Here is how I correct the issue:
$_POST = json_decode(file_get_contents("php://input"), true);
这篇关于php $_POST 数组在表单提交时为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!