Home » PHP » PHP Tutorial: The Raw Post Contents Part 1

PHP Tutorial: The Raw Post Contents Part 1

There are certain times when you need to retrieve raw post contents rather than getting them from the $_POST array. This happened to be when I was being fed e-mail addresses that might have a plus in them and found that PHP was automatically running urldecode() on them. That turns the pluses into spaces, and I needed to differentiate between the two.

That's when I discovered this:

file_get_contents("php://input");

It will return the raw, undecoded post contents. Unfortunately, it doesn't parse them into a nice array and using a function like parseurl will run urldecode() on them. So, you'll probably need to use a regular expression to extract the values from the raw post data.

And since I'm typing this on a bus while going to a JavaScript game developers meetup (my 7 year old wants me to help him make a game this summer), I'll address the regular expression to do that tomorrow.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>