Tuesday, December 20, 2016

json_decode(file_get_contents("php://input") on https

When you try to run json_decode on https, it will throw errors due to null value. file_get_contents("php://input") will also return null.

Way to solve it and the most efficient are as follows

//get data from caller
$arrContextOptions=array(
 "ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);  
$your_data_array= json_decode(file_get_contents("php://input",false, stream_context_create($arrContextOptions)),true);

The code actually make it don't care what protocol you are using and set it to false (means no verifications). It normally happen when you are using self-signed or non-standard SSL certificates.

It is the most efficient and the fastest solutions.. but not the most practical :)

The best is -> use standard approved certificates :)

Share It

Popular Posts