Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Settings? PHP not receiving POST data

Tags:

post

php

I’m sending a .php file POST data from a java application. The .php file is not accepting the POST data. file_get_contents(‘php://input’) is empty and $_POST is empty. I know the problem isn’t with the .php file or java application because I tested it using a different host and it worked. Is there a setting in php.ini I’m missing or a setting I need to change?

like image 564
Sam Avatar asked Aug 03 '11 08:08

Sam


2 Answers

If the Content-Type is empty or not recognized in the HTTP message then the PHP $_POST array is empty. If you cannot send the Content-Type you can add this to your PHP:

if(empty($_SERVER['CONTENT_TYPE']))
{ 
 $_SERVER['CONTENT_TYPE'] = "application/x-www-form-urlencoded"; 
}

You can also check if you have the correct settings in your php.ini

; Maximum size of POST data that PHP will accept.
post_max_size = 8M

If post_max_size is 0, PHP will not populate $_POST.

variables_order = "EGPCS"

If you do not have P in there, $_POST will not be set either.

like image 170
Claude Schlesser Avatar answered Oct 15 '22 18:10

Claude Schlesser


I had this problem too. For future visitors, my issue was missing the trailing slash in the url. Eg..

http://someplace.com/cheeseburger

should have been...

http://someplace.com/cheeseburger/

This was causing the post to fail, in my case.

like image 35
I wrestled a bear once. Avatar answered Oct 15 '22 18:10

I wrestled a bear once.