CodeIgniter Forums
Impossible to use AJAX on PHP 5.6 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Impossible to use AJAX on PHP 5.6 (/thread-66950.html)



Impossible to use AJAX on PHP 5.6 - pex - 12-21-2016

So I have a PHP version that is affected to the bug of "always_populate_raw_post_data"...

In few words if i set headers after I display content, my app just return an error and stop working.

I need to get some data from ajax, but the problem is that the controller where ajax suppose to work, extend CI_Controller that set some headers, This return me an error:

Code:
<b>Deprecated</b>:  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 <b>Unknown</b> on line <b>0</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent in <b>Unknown</b> on line <b>0</b><br />


How can I solve it? I should find a way to prevent this header to be set...

Thanks in advantage..


RE: Impossible to use AJAX on PHP 5.6 - ivantcholakov - 12-21-2016

Upgrade CodeIgniter.


RE: Impossible to use AJAX on PHP 5.6 - pex - 12-22-2016

(12-21-2016, 07:00 PM)ivantcholakov Wrote: Upgrade CodeIgniter.

Hi! Thanks for your reply, I'm actually using the last version of CodeIgniter (3.1.2).

Problem is on PHP but I can't update it.

Is it possible that in CodeIgniter there is no way to use AJAX without passing for a CI_Controller?

Or without setting headers by default from the controller, eventually..


RE: Impossible to use AJAX on PHP 5.6 - ivantcholakov - 12-22-2016

Hm. Switch temporarily CodeIgniter to 'production' mode to test whether this message disappears. Then turn back to 'development' to see this message again. Looks like there is a wrong PHP configuration setting, always_populate_raw_post_data - check what is its value. See how the following information might help:

https://github.com/bcit-ci/CodeIgniter/issues/3254
https://github.com/piwik/piwik/issues/6465


RE: Impossible to use AJAX on PHP 5.6 - pex - 12-23-2016

(12-22-2016, 10:46 AM)ivantcholakov Wrote: Hm. Switch temporarily CodeIgniter to 'production' mode to test whether this message disappears. Then turn back to 'development' to see this message again. Looks like there is a wrong PHP configuration setting, always_populate_raw_post_data - check what is its value. See how the following information might help:

https://github.com/bcit-ci/CodeIgniter/issues/3254
https://github.com/piwik/piwik/issues/6465

Thanks! I checked them and I know the problem is on the PHP configuration. Problem here is again that I can't modify it, the admin is very "conservative" and doesn't want to modify the global setup of environment since other applications are working fine.

As explained here
http://stackoverflow.com/questions/28278705/always-populate-raw-post-data-trouble-accessing-request-payload-from-backbone
"Some claim it happens when calling 
Code:
header()
 after some text has already been outputted."
And actually when i create my controller, extends from CI_Controller, there are new headers set automatically.

I wish then try to find a solution to avoid this header to be sent..


RE: Impossible to use AJAX on PHP 5.6 - InsiteFX - 12-23-2016

.htaccess file try adding this:

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



RE: Impossible to use AJAX on PHP 5.6 - pex - 12-23-2016

(12-23-2016, 05:40 AM)InsiteFX Wrote: .htaccess file try adding this:

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

The server use Fastcgi, and I don't even have override permission set on my webdir. Sadly.

Anyway, the solution that could work for me is: prevent the controller to add this header or remove them, if it's possibile.

Other's AJAX applications are working but mine, built with CodeIgniter, doesn't.

I tried to find where this headers are set on the system/ directory to remove them, trying to find a way to let CodeIgniter understand that I don't want headers if the controller has name "Ajax" but I couldn't find anything.


RE: Impossible to use AJAX on PHP 5.6 - pex - 12-23-2016

Ok I found my solution, for everyone interested I just change my AJAX request from POST to GET.. Cause actually I didn't even send any data.. My error, I suppose Smile

Anyway, with GET it works anyway, without need to change settings on apache config.

Thanks everybody for the help Smile


RE: Impossible to use AJAX on PHP 5.6 - ivantcholakov - 12-23-2016

Then you need to watch about browser caching for AJAX GET, disable caching for certain requests when the logic requires.

Code:
$.ajax({
    cache: false,
    ...
});