问题描述
我有一个自定义的CMS我建立的一个对我开发框完美的作品(Ubuntu的/ PHP5 + / MySQL5的+)。
I have a custom 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://输入');
键,数据显示有罚款 - 在 $ _ 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.
我也验证了内容类型标头是正确的,以及通过萤火(应用程序/ x-WWW的形式urlen codeD;字符集= 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.
任何帮助是极大AP preciated!
Any help is greatly appreciated!
推荐答案
我知道这个问题是关于通过表单POST,但JSON内容类型发帖时来到这里寻找类似问题的答案。找到了答案,并希望分享它,因为它花了我很多时间。
I know this question was about POST via a Form, but came here looking for answers for similar issue when POSTing with JSON content-type. Found the answer and wanted to share it as it cost me much time.
在使用JSON内容类型$ _POST数组将不填充(仅与多部分的形式,我相信)
When using JSON content-type the $_POST array will not populate (only with multi-part forms I believe)
下面是没有工作来解决此问题:
Here is what did work to correct the issue:
$rest_json = file_get_contents("php://input");
$_POST = json_decode($rest_json, true);
希望这可以帮助别人!
hope this helps someone!
这篇关于PHP的$ _POST数组提交表单空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!