php://input works correctly in localhost. But on the server, it returns empty. The input (request) to my site is json (REST - application / json type), so $_POST did not work (please read this question ).
$ _ POST works with key-value pair inputs such as form data or x-www-urlencoded
key1 = value1 & key2 = value2 & key3 = value3
I use application/json as input (in REST ).
Like {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
This is not possible with $_POST . But using php://input can help read this data.
My code
class Webservice_Controller extends CI_Controller { public $json_input_data; public function __construct(){ parent::__construct(); $this->json_input_data = json_decode(file_get_contents('php://input'),TRUE); } public function json_input($label){ if(isset($this->json_input_data[$label])) return $this->json_input_data[$label]; else return NULL; } }
The above code works fine on another web server, but not in the current one :(
I think my web server is denying access to php://input .
Are there any other methods for reading json input in php?
source share