php var_dump($_POST); 为空但不是 var_dump($_POST); 死;

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7547840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:55:56  来源:igfitidea点击:

var_dump($_POST); is empty but not var_dump($_POST); die;

phppost

提问by sentinel777

i have found some similar topics on this issue, but nothing for my case:

我在这个问题上发现了一些类似的主题,但对我的情况没有任何帮助:

i send some post data via form, but the $_POST array is always empty (not null). but when i add a "die;" or "exit;" after var_dump($_POST); i can see all data sent.

我通过表单发送一些帖子数据,但 $_POST 数组始终为空(不为空)。但是当我添加一个“死;” 或“退出”;后 var_dump($_POST); 我可以看到所有发送的数据。

maybe its relevant to know, that this is inside a (shopware) plugin which is called on "onPreDispatch".

也许它相关知道,这是在“onPreDispatch”上调用的(shopware)插件内。

thanks for any help

谢谢你的帮助

回答by Tadej Magajna

Your (shopware) plugin probably uses output buffering. Which means it will gather all the ecoes and prints until you call ob_flush() which prints all the buffer.

您的(商店软件)插件可能使用输出缓冲。这意味着它将收集所有 ecoes 并打印,直到您调用 ob_flush() 打印所有缓冲区。

die() function, apart from everything else, also flushes the buffer when called. So, if you do ob_flush() after your echo you should get the needed result.

die() 函数除了其他所有功能外,还会在调用时刷新缓冲区。所以,如果你在你的回声之后做 ob_flush() 你应该得到需要的结果。

回答by sentinel777

the problem was the redirect, which resetted the post although it was after i read the parameters in the request.

问题是重定向,它重置了帖子,尽管它是在我阅读请求中的参数之后。

i did not know, that shopware saves the desired data (paymentID) in the database. so i switched my plugin back to "onPostDispatch" (this way it will be called after all other actions, one of them saves the data in db). now i can just read the db and get the same data, which was initially in the post array.

我不知道,shopware 将所需的数据(paymentID)保存在数据库中。所以我将我的插件切换回“onPostDispatch”(这样它会在所有其他操作之后被调用,其中一个将数据保存在 db 中)。现在我可以读取 db 并获得相同的数据,这些数据最初位于 post 数组中。

i tried to be "the first" who reads the post, but could not work it out. now i am the last who reads it and it works fine.

我试图成为阅读帖子的“第一个”,但无法解决。现在我是最后一个阅读它的人,它运行良好。

thanks for all answers! the clue here was "redirect".

感谢所有的答案!这里的线索是“重定向”。