Search code examples
phpfile-get-contents

file_get_contents('php://input') not working. Empty - NULL


I having this problem for the last 12 hours, i read about 50 articles, 50 questions here, i can't fix it. I will be more precise, i want others get the solution too.

The problem: I have a hosting account in namech****, and a local server. Linux there and Xampp Windows here, this only works in my local server.

test.php:

<?php    
    $data = json_decode(file_get_contents("php://input"), true);
        var_dump($data);
?>

The post request is:

POST /test.php HTTP/1.1
Host: myweb.io
Content-Type: application/json
Content-Length: 77

{
  "test": "product/created",
  "other": "https://google.com/"
}

I use REQBIN for test the POST request.

This is the response in my hosting:

HTTP/1.1 200 OK
Date: Sun, 03 May 2020 17:04:33 GMT
Server: Apache
X-Powered-By: PHP/7.4.5
Content-Encoding: gzip
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

NULL

This is the correct response on my local enviroment using XAMPP

HTTP/1.1 200 OK
Date: Sun, 03 May 2020 17:15:19 GMT
Server: Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.4.3
X-Powered-By: PHP/7.4.3
Content-Length: 94
Content-Type: text/html; charset=UTF-8

Array
(
    [test] => product/created
    [other] => https://google.com/
)

Things i've tried:

  • Set the allow_url_fopen to 1, or 0.
  • Downgrade PHP versión (Tried 7.1,2,3,4)
  • Uninstall SSL Certificate
  • Millions of things in PHP.INI
  • Removing htaccess
  • Removing some php modules / extensions UPDATE:
  • The file is individual, cheched that the function is only execute one time
  • I check if there are no redirections. (Htaccess, cPanel settings)

Solution

  • I fix it, don't know how, but i think the solution was: Delete my htaccess completely, no redirections (http to https). Dont test with reqbin, test it with php pure code, or PostMan.