9

DUPLICATE NOTE: This is not IMO a duplicate of this question because I lookaed at that first and did not find an answer to the question there. If you do find it, please let me know exactly where.

In PHP, as we know, the superglobal $_POST[] is an array that will contain the result of parsing incoming HTTP request body for the mime types of either

  • application/x-www-form-urlencoded (standard content type for simple form-posts) or
  • multipart/form-data-encoded (mostly used for file uploads)

If our client is sending anything else as a request we need to take care of the parsing ourselves by using the string returned from file_get_contents('php://input');.

Now here is my question; let's say that I don't know what mimetype my request contains. Can I use $_POST and php://input interchangeably? Or to be more specific, will reading from php://input interfere with the population of $_POST[], or will accessing $_POST[] somehow disrupt or disable php://input?

Community
  • 1
  • 1
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
  • 6
    have you seen/read this http://stackoverflow.com/questions/8893574/php-php-input-vs-post - Read it if you haven't. If it answers the question, I'll mark it as a duplicate. – Funk Forty Niner Nov 25 '15 at 04:12
  • Yes, in fact I was looking at that when forming my question because even though both the question and answers there are excellent I felt that the topic of my question had been elegantly avoided, and was important enough to warrant it's own question on S.O. – Mr. Developerdude Nov 25 '15 at 04:14
  • No problemo Lennart, *cheers* – Funk Forty Niner Nov 25 '15 at 04:15
  • Have a look on it. might be satisfies your doubt http://stackoverflow.com/questions/2731297/file-get-contentsphp-input-or-http-raw-post-data-which-one-is-better-to – Vigneswaran S Nov 25 '15 at 04:15
  • I hereby express my utmost frustration over having this question marked as a duplicate. It is not a duplicate because the question is not answered in the other link :) – Mr. Developerdude Nov 25 '15 at 15:32

0 Answers0