0

so i was working on a very simple post request method like this

<form action="index.php" method="POST"> password:<input type="password" name="password"> <input type="submit" value="submit"> <form/>

and when i open it on my browser and click submit it displays the following error enter image description here

and before you say anything, yes i set

always_populate_raw_post_data = -1

as seen below: enter image description here

but still the error keeps on popping.......HELP please!!!

Harun
  • 65
  • 10
  • 4
    Is there a reason for not using `$_POST`? – Dekel Aug 25 '16 at 13:59
  • yes, i just wanna try the post method out.... and the funny thing is when i change the method = "GET" it actually works perfectly. – Harun Aug 25 '16 at 14:02
  • @Harun show us the php file code – Lokesh Pandey Aug 25 '16 at 14:03
  • @mario I googled around a bit and it seems to work for other people – Harun Aug 25 '16 at 14:08
  • @Lokesh the only code i have in my editor is the one i included in my question – Harun Aug 25 '16 at 14:08
  • Uncomment the line in php.ini file always_populate_raw_post_data = -1 – Lokesh Pandey Aug 25 '16 at 14:11
  • I'm going to guess you've restarted your web server after making the changes. Create a new file with the contents `` and navigate to that page to verify the settings have saved. You can also make sure that you're editing the correct php.ini file. – aynber Aug 25 '16 at 14:12
  • @Harun the same issue has been discussed here!! http://stackoverflow.com/questions/26261001/warning-about-http-raw-post-data-being-deprecated – Lokesh Pandey Aug 25 '16 at 14:14
  • @Harun And after making the changes to php.ini file restart the server – Lokesh Pandey Aug 25 '16 at 14:14
  • 3
    Form the manual: **This feature was DEPRECATED in PHP 5.6.0, and REMOVED as of PHP 7.0.0.** Dont waste your time on it – RiggsFolly Aug 25 '16 at 14:15
  • @mario That's not correct. [It has to be -1 to disable it fully](http://stackoverflow.com/a/26261002/2370483) – Machavity Aug 25 '16 at 14:19
  • As I recall, this message pops up in the error logs of certain versions of PHP whether or not you're using the variable, just like if you don't set the timezone in the ini. – aynber Aug 25 '16 at 14:22
  • @Machavity Oh. You're right. The [boolean check](https://github.com/php/php-src/blob/4797f7ad16bc65bda9dca10232c8e0c62a6830ea/main/php_content_types.c) is somewhat diffuse. – mario Aug 25 '16 at 14:37

2 Answers2

1

From the link in the config file:

If set to TRUE, PHP will always populate the $HTTP_RAW_POST_DATA containing the raw POST data. Otherwise, the variable is populated only when the MIME type of the data is unrecognised.

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.

Regardless of the setting, $HTTP_RAW_POST_DATA is not available with enctype="multipart/form-data".

As per the documentation setting it to -1, rather than TRUE uses the PHP 7.0 version which doesn't even define $HTTP_RAW_POST_DATA.

Anyway, as also mentioned in the documentation, you really should just be using file_get_contents("php://input"); to read the raw POST data.

Community
  • 1
  • 1
Phylogenesis
  • 7,775
  • 19
  • 27
  • can you show me how i can use that in my particular case??? – Harun Aug 25 '16 at 14:16
  • I did: `$postData = file_get_contents('php://input');` – Phylogenesis Aug 25 '16 at 14:24
  • and where do i put that exactly?? – Harun Aug 25 '16 at 14:36
  • @Harun - `php://input` is a direct replacement for `$HTTP_RAW_POST_DATA`. Use `file_get_contents()` to read it. See the manual entries [for $HTTP_RAW_POST_DATA](http://php.net/manual/en/reserved.variables.httprawpostdata.php) and [for php://input](http://php.net/manual/en/wrappers.php.php#wrappers.php.input). – Spudley Aug 25 '16 at 15:35
  • Also note that it hasn't just been deprecated, but it has actually been removed entirely from PHP 7.0, so if you want your code to continue working, you absolutely must switch to the newer method. The same applies to other deprecated features. – Spudley Aug 25 '16 at 15:36
1

I was actually editing the wrong php.ini file as there are a bunch of them inside the Wamp folder... though the right one is found by clicking Wamp in your toolbar ->PHP->php.ini file and set the always_populate_raw_post_data = -1, then everything will work perfectly

Harun
  • 65
  • 10