I know I must be doing something simple wrong. I'm just trying to echo the value of $HTTP_RAW_POST_DATA.

Here is my test form:

<form action="quicktest.php" method="post" mimetype="text/xml" enctype="text/xml" name="form1">
<br>
<input name="hey" type="text" id="hey" value="nothing met">
<input type="submit" name="Submit" value="Submit">
</form>

Here is my PHP code on quicktest.php

<?php        
print "$HTTP_RAW_POST_DATA<br>"; ?>

When I try and echo or print $HTTP_RAW_POST_DATA I get nothing, anyone have the solution to why this wont work ?

    1. It doesnt exist.
    2. It belongs to the $_SERVER superglobal array.

    As I've never come across it before, I'd go for (1).
    Still, it might exist in your case, upon which (2) is likely to be the answer, so you should use $_SERVER['HTTP_RAW_POST_DATA']

      Well, I tried your advice and for some reason I'm still not getting anything.

      This is what I'm using:

      <?php
               $theinfo = $_SERVER['$HTTP_RAW_POST_DATA'];
      		echo $theinfo;
      ?>
      

      I'm using the same form as above, and ideas ?

        From the user comments in the PHP manual for predefined variables where $HTTP_RAW_POST_DATA is discussed.
        It should be noted that $HTTP_RAW_POST_DATA only exists if the encoding type of the data is -not- the default of application/x-www.form-urlencoded, and so, to accessing raw post data from an HTTP form requires setting enctype= in your HTML.

        Try setting the enctype to text/xml and see if that helps any.

        Also, it's in the $GLOBALS array, so try $GLOBALS['HTTP_RAW_POST_DATA'] instead.

          Changing the enctype was one of the first things I tried. If you look at my first post it was already set to "enctype="text/xml"

          This is what my form looks like:
          <form action="quicktest.php" method="post" enctype="text/xml" name="form1">
          <br>
          <input name="hey" type="text" id="hey" value="">
          <input type="submit" name="Submit" value="Submit">
          </form>

          This is what my PHP looks likes now:

          <? $GLOBALS['HTTP_RAW_POST_DATA']; ?>
          <?php echo $GLOBALS ?>
          <?php echo $HTTP_RAW_POST_DATA ?>
          

          I'm still not getting anything to echo, I also tried it this way:

          <? $theinfo= $GLOBALS['HTTP_RAW_POST_DATA']; ?>
          <?php echo $theinfo ?>
          

          and still nothing to echo. Now I'm getting frustrated wondering why something this simple is not working.

            The $GLOBALS is an array so you wouldn't get anything by echoing it out.

            Try print_r($GLOBALS); and see what's in the array. You may find something in there that you can use.

              Thanks Defender!

              The code you gave me does seem to work (<?php print_r($GLOBALS); ?>). Only problem is it prints all header info and everything else I dont need along with what was posted.

              However, I found this also: <?php print_r($_POST); ?>

              It works perfect in regards to printing everything to the screen, my only problem is storing it in an variable . . . I tired

              <?php $theinfo=($_POST); ?> with no luck, any ideas on this ?

                if HTTP_RAW_POST_DATA is in $POST, then use it as $POST['HTTP_RAW_POST_DATA']

                  I don't think HTTP_RAW_POST_DATA is in the $POST array laserlight. I think he meant that he found the posted data he was looking for in the $POST array (imagine that)

                  thehb, to get what you need, call it by it's index name:

                  <?php
                  echo $_POST['variable1'];
                  echo $_POST['variable2'];
                  ?>
                  

                    Yea, calling it by it's name is the problem. This info that will be posted to this page has no name, it's XML . . heed the need to pick up RAW data and store it in a variable. Basically the entire page is complete except for this par, still not getting anywhere with it.

                      You could try php://input a stream / wrapper function - but you must have a recent version of php. (php4.3.0+)

                      Less intensive than $HTTP_RAW_POST_DATA and doesnt require any ini settings!

                      Check it out:

                      http://www.php.net/wrappers.php

                        Ok, after making some changes to php.ini I have $HTTP_RAW_POST_DATA working. :rolleyes:

                        It's picking up the posted data as it should, the only problem now is how it's displaying it. Remember, this is just a test, the XML will be sent by an outside server in the near future.

                        My form looks like this (page1.html):

                        <input name="test" type="hidden" id="test" value="<ProvisionRequestStreamClosure>
                        <ServiceNumber>2145292436</ServiceNumber>
                        </ProvisionRequestStreamClosure>">

                        When I echo $HTTP_RAW_POST_DATA it's pringing like this (page2.php):

                        +=%3CProvisionRequestStreamClosure%3E%0D%0A%3CServiceNumber%3E2145292476%3C%2FServiceNumber%3E%0D%0A%3C%2FProvisionRequestStreamClosure%3E&Submit=Submit

                        Why is it changing the < and > to %3E and things of that sort ?

                          No doubt because it's being submitted with the default form data MIME type (text/urlencoded or something like that - I forget exactly and I'm not going to look up the HTML spec right now); so try using [man]urldecode[/man].

                            3 years later

                            will u please tell what changes u have done in php.ini file
                            i make one change "always_populate_raw_post_data" set as "on" in php.ini file
                            but still i have not got output

                            thehb wrote:

                            Ok, after making some changes to php.ini I have $HTTP_RAW_POST_DATA working. :rolleyes:

                            It's picking up the posted data as it should, the only problem now is how it's displaying it. Remember, this is just a test, the XML will be sent by an outside server in the near future.

                            My form looks like this (page1.html):

                            <input name="test" type="hidden" id="test" value="<ProvisionRequestStreamClosure>
                            <ServiceNumber>2145292436</ServiceNumber>
                            </ProvisionRequestStreamClosure>">

                            When I echo $HTTP_RAW_POST_DATA it's pringing like this (page2.php):

                            +=%3CProvisionRequestStreamClosure%3E%0D%0A%3CServiceNumber%3E2145292476%3C%2FServiceNumber%3E%0D%0A%3C%2FProvisionRequestStreamClosure%3E&Submit=Submit

                            Why is it changing the < and > to %3E and things of that sort ?

                              you could just use this:-

                              if (!isset($HTTP_RAW_POST_DATA))
                                 $HTTP_RAW_POST_DATA = file_get_contents("php://input");

                              😉

                                Write a Reply...