Raw POST Data in PHP

January 5th, 2006

Sometimes, albeit rarely, I've needed to get at the raw POST data in a PHP file. You can of course get the POST data using $_POST, however, this is after PHP has processed it (i.e. magic quotes may have been applied, thus escaping the data). You can access the raw POST information using the following:

PHP:
  1. $data = file_get_contents("php://input");

You can access the php://input wrapper as if it were a file, and use the Filesystem functions. More information on the PHP wrappers can be found in the PHP Manual.


 Add to del.icio.us    Digg this    Technorati

Related Posts:

Entry Filed under: PHP

4 Comments Add your own

  • 1. Darrell  |  January 28th, 2006 at 10:10 pm

    I am a Telephony Developer having a problem
    getting data POSTED back to us. We have a VB script
    that we use to POST an XML string to an SMS provider.
    When they POST back to us, we do not get any data.
    We tried to simulate this POST by pointing the VB
    script back at us, and it doesn't work either.
    We have an HTML submit form that calls our PHP
    script,

    Do I need the submit tag? If so, how should this
    look? If I manually enter data, it works fine, but
    the VB POST does not. Do I need to get
    :RAW_POST_DATA or something from STDIN ?
    Help, if you can. Thank you.

  • 2. Tyron  |  January 10th, 2008 at 6:17 pm

    Thanks a lot this small hint, saved me quite a load of time!

  • 3. Shai Mishali  |  April 16th, 2008 at 8:35 am

    If talking about an HTML form, a submit button MUST be present in order to send the form's post data.

    Or a "submit" type input or a "image" (which is a submit in the form of an image)

    You can hide it if it bothers you:

    Cheers,
    Shai.

  • 4. Emons  |  April 18th, 2008 at 10:50 pm

    I'm writing a client/server application where the client is written in Delphi and the server is a standard webserver with PHP (or any other server side scripting language). This tips made my life easier as I now don't have to use a dummy POST variable name to send my XML data.

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

January 2006
M T W T F S S
« Dec   Feb »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Most Recent Posts