简体   繁体   中英

How to fix PHP Deprecated Automatically populating $HTTP_RAW_POST_DATA is deprecated issue?

hello i'm getting this error in my error log:

" PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0 "

My wordpress version is 4.8.1 and the php version is 5.6.30.

I tried fixing the issue by creating a php ini file and setting always_populate_raw_post_data value to -1. But i still get the error.

If it cannot be fixed , how can i prevent it prints on the error log?

I'm using a shared hosting.

If your Account (on the shared hosting) using (or Configured) PHP-FPM, you can't do it via php.ini (if you create php.ini in your root, it will have no effect)

you can try: add this code

<IfModule mod_php5.c>
    php_value always_populate_raw_post_data -1
</IfModule>

in your .htaccess file in your root directory, if not helps then ask the server admin (support) to change that in core php.ini globally for the given host.

The php.ini file you created needs to be located where PHP expects to find its config files. You can see the configs which PHP is already loading using the phpinfo() function:

Upload a file named info.php with the following contents to your web server root:

<?php
// delete this file or comment out the below function when not in use
phpinfo();
?>

Then use a browser to navigate to http://yourwebsite.com/info.php . A page should load which tells you all about your php configuration. Look for the part near the top which shows information about the loaded configuration files. In particular, look for these entries: "Loaded Configuration File" and "Scan this dir for additional .ini files" .

If you have access to the .ini file listed as the Loaded Configuration File simply modify the value for always_populate_raw_post_data there. Otherwise, upload the .ini file you already created to the directory that is scanned for additional configuration files. Of course, you'll need to reload or restart php in order to reparse the configuration files.

If you don't have access to any of the locations listed from the above steps, it's possible your hosting provider may give you access to your php.ini file through cPanel or a similar means. Otherwise, your best bet is to contact them directly.

Finally, if you don't care about the actual configuration value as much as just suppressing the warning message, you could use the ini_set() function to set your error reporting to a different value, eliminating any deprecation warnings. The variable you want to set is "error_reporting" and a list of possible values can be found here .

In addition, since you are running WordPress there are some debug and error reporting options you can set in the wp-config.php file.

You cant create a PHP.ini just like that. This is a core config file that is part of the PHP install. http://php.net/manual/en/configuration.file.php Read over this documentation to get a better idea of what the ini does.

The ini file could be located in multiple places depending on the OS and who installed it. If you do not have access to it, talk to your hosting provider

how can i prevent it prints on the error log?

Your problem here is not that you cannot access php.ini and it is not that error shows.

Your problem, in fact, is that you use deprecated variable

instead, you could try using

file_get_contents('php://input');

php.ini is located somewhere in the php files on the server, which I assume you have no access to on shared hosting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM