开发者

PHP script to log the raw data of POST

I am sending data using HTTP POST to my server. But in the server, I am not receiving the data. And somehow I don't have any way to check the data (or debug script) on client side. But on the client side I am getting HTTP 200, meaning data is sent. Also I can see the connection and data sending was successful. However, log in the server doesn't contain the data (only the number of bytes).

How 开发者_StackOverflow社区can I log the raw POST data that was sent to the server?

FYI, here the client is an embedded device with very limited capability, so this is a problem. I can not check "print_r" or "echo".


You can see the content of POST data inline (not for production) with:

print_r($_POST);

Or if you want to see POST, GET and COOKIE data:

print_r($_REQUEST);

If you need to log, since the client is very limited - try outputting the POST data to a file:

file_put_contents("post.log", print_r($_POST, true));


Write POST data to a file:

file_put_contents('/tmp/postdata.txt', var_export($_POST, true));


You can try sniffing the HTTP session.


To get the raw post from php you must use file_get_contents("php://input").

This will allow you to capture the raw body of the request, instead of form-data only ($_POST).

That said, you can use

file_put_contents("post.log", file_get_contents("php://input"));

This will allow you to log POST requests with Json data, and other stuff in its body.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜