14

I am sending data using the HTTP POST verb . But I am not receiving the data server side, despite the client reporting status-code 200. I can see the connection, and that the data was successfully sent, however, on the server, the data isn't found, with the log showing only the number of bytes.

How 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.

Rudu
  • 15,682
  • 4
  • 47
  • 63
Morison
  • 1,145
  • 3
  • 18
  • 35
  • What happens if you try a print_r($_POST)? – Martin Hennings Sep 15 '10 at 13:56
  • unfortunately I can not see that in client side. So,it will not work. – Morison Sep 15 '10 at 13:59
  • Were you able to reproduce the problem with some other client that is more potent (and able to run things like firebug ^^)? – Martin Hennings Sep 15 '10 at 14:03
  • Wait - so it's a closed server (you cannot get access) you're sending data but you don't know why it's not showing? This is a black box problem - the software could be doing ANYTHING to your data including ignoring it, storing it somewhere else, encoding it, cleaning the kitchen sink with it - this isn't a PHP or MySQL question in that case. – Rudu Sep 15 '10 at 14:03
  • @Rudi - I don't think that he's on a closed server. Just the problem that any debugging information can only be output to either some data storage (SQL, file, ...) or to the caller (who is unable to display that data). – Martin Hennings Sep 15 '10 at 14:10
  • yeah, that's right. Thanks Martin. Sorry, I forgot to respond on Rudi's comment. – Morison Sep 15 '10 at 15:05

4 Answers4

35

You can see the content of any data sent with the post verb (not for production) with:

print_r($_POST);

If you want to see data from the verbs get, post, cookie:

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));
file_put_contents("gpc.log", print_r($_REQUEST, true));
Rudu
  • 15,682
  • 4
  • 47
  • 63
15

Write post data to a file:

file_put_contents('/tmp/postdata.txt', var_export($_POST, true));
Sjoerd
  • 74,049
  • 16
  • 131
  • 175
3

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.

Ricardo Martins
  • 5,702
  • 3
  • 40
  • 59
1

You can try sniffing the HTTP session.

Sjoerd
  • 74,049
  • 16
  • 131
  • 175