Warning About '$Http_Raw_Post_Data' Being Deprecated

Warning about `$HTTP_RAW_POST_DATA` being deprecated

It turns out that my understanding of the error message was wrong. I'd say it features very poor choice of words. Googling around shown me someone else misunderstood the message exactly like I did - see PHP bug #66763.

After totally unhelpful "This is the way the RMs wanted it to be." response to that bug by Mike, Tyrael explains that setting it to "-1" doesn't make just the warning to go away. It does the right thing, i.e. it completely disables populating the culprit variable. Turns out that having it set to 0 STILL populates data under some circumstances. Talk about bad design! To cite PHP RFC:

Change always_populate_raw_post_data INI setting to accept three values instead of two.

  • -1: The behavior of master; don't ever populate $GLOBALS[HTTP_RAW_POST_DATA]
  • 0/off/whatever: BC behavior (populate if content-type is not registered or request method is other than POST)
  • 1/on/yes/true: BC behavior (always populate $GLOBALS[HTTP_RAW_POST_DATA])

So yeah, setting it to -1 not only avoids the warning, like the message said, but it also finally disables populating this variable, which is what I wanted.

Error $HTTP_RAW_POST_DATA is deprecated, use the php://input stream instead.

The solution to this problem was editing the right php.ini. Then everything worked.

Why is $HTTP_RAW_POST_DATA being called?

Here's the relevant C code with my comments:

static zend_bool populate_raw_post_data(TSRMLS_D)
{
// not a post, empty request - return FALSE
if (!SG(request_info).request_body) {
return (zend_bool) 0;
}

// if always_populate_raw_post_data=0 then
// if we don't know how to parse the post (unknown mimetype) return TRUE
// otherwise (known mimetype) return FALSE
if (!PG(always_populate_raw_post_data)) {
return (zend_bool) !SG(request_info).post_entry;
}

// if always_populate_raw_post_data > 0 return TRUE
// if always_populate_raw_post_data < 0 return FALSE
return (zend_bool) (PG(always_populate_raw_post_data) > 0);
}

That is, setting always_populate_raw_post_data to 0 still enables populating for unknown content types. You have to use a negative value to skip it altogether.

This is now documented in the manual:

The preferred method for accessing raw POST data is php://input, and $HTTP_RAW_POST_DATA is deprecated in PHP 5.6.0 onwards. Setting always_populate_raw_post_data to -1 will opt into the new behaviour that will be implemented in a future version of PHP, in which $HTTP_RAW_POST_DATA is never defined.

$_POST Method didn't work

  1. You forgot to give Space.
  2. Also check variable existence.

      <form method="post" action="index.php">
    <input type="text" name="tb"/>
    <input type="submit" value="Send"/>
    </form>

    <?php
    echo $tb = isset($_POST['tb']) ? $_POST['tb'] : "";
    ?>

Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated

sorry thanks you were right :)

$_REQUEST['id'] -> took away the error

// get id of product to be edited

$data = json_decode(file_get_contents("php://input")); 

replaced json_decode(file_get_contents("php://input")); this with this $_REQUEST['id']

Ajax load PHP $HTTP_RAW_POST_DATA is deprecated

The problem is solved after change Post to GET

$(window).load(function() {
$.ajax({
url: '/js/js.php',
type:'GET',
cache: false,
success: function(data){
if(data){
$('body').append(data);
}
}
});
})


Related Topics



Leave a reply



Submit