PHP $_POST is empty even though the form or client sent data
$_POST is an empty arrayShort answer
PHP fills $_POST only for application/x-www-form-urlencoded and multipart/form-data. A JSON body needs php://input. $_POST is also empty when the body is larger than post_max_size, when enable_post_data_reading is off, or when a redirect turned the POST into a GET. Check the request's Content-Type first.
Fix it fast
1Find out which cause you have
Dump what PHP received: the request method, the content type, and the raw body size. This shows which cause applies.
<?php var_dump($_SERVER['REQUEST_METHOD'], $_SERVER['CONTENT_TYPE'] ?? null, $_SERVER['CONTENT_LENGTH'] ?? null, $_POST); var_dump(strlen(file_get_contents('php://input')));2Match what you see, then jump to its fix
- 1
CONTENT_TYPE is application/json and the raw input contains your data.The body is JSON, not form dataFix - 2
CONTENT_LENGTH is larger than post_max_size (default 8M); $_POST and $_FILES are both empty, usually on a file upload.The request body is bigger than post_max_sizeFix - 3
$_POST is empty for every request, even small form posts, and the raw input has the data.enable_post_data_reading is turned offFix - 4
REQUEST_METHOD is GET in the dump, although the form used POST, and the URL was redirected (for example http to https).A redirect changed the POST into a GETFix
- 1
What does the error look like?
$_POST is an empty arrayvar_dump($_POST) prints array(0) {}
Cause 1 of 4
The body is JSON, not form data
1Check
$_POST only works with application/x-www-form-urlencoded or multipart/form-data. Any other content type, such as JSON, is not parsed into it.
curl -s -X POST -H "Content-Type: application/json" -d '{"name":"a"}' https://example.com/api.php2Fix
Read the raw body and decode it.
$data = json_decode(file_get_contents('php://input'), true);3Verify
The decoded array contains your fields.
var_dump($data);Confirmed by php.net
Cause 2 of 4
The request body is bigger than post_max_size
1Check
If the post data is greater than post_max_size, $_POST and $_FILES are empty and PHP raises no error.
php -r "echo ini_get('post_max_size');"2Fix
Raise post_max_size above upload_max_filesize in php.ini (it is a per-directory setting, so ini_set() at runtime does not work), then restart PHP.
; php.ini
post_max_size = 64M
upload_max_filesize = 32M3Verify
Repeat the upload; the arrays are filled.
php -r "echo ini_get('post_max_size');"Confirmed by php.net
Cause 3 of 4
enable_post_data_reading is turned off
1Check
With this option disabled, $_POST and $_FILES are not populated and the body stays available in php://input.
php -r "var_dump(ini_get('enable_post_data_reading'));"2Fix
Remove the override or set it back to 1, unless you really want to parse the body yourself.
; php.ini
enable_post_data_reading = 13Verify
A normal form post fills $_POST.
curl -s -d "name=a" https://example.com/form.phpConfirmed by php.net
Cause 4 of 4
A redirect changed the POST into a GET
1Check
For a 301 the user agent may change the method from POST to GET. A 308 does not allow that.
curl -sI -X POST http://example.com/form.php2Fix
Post straight to the final URL, or make the redirect a 308 instead of a 301.
# the form action should already be the final https address
<form action="https://example.com/form.php" method="post">3Verify
REQUEST_METHOD is POST and $_POST has the fields.
curl -s -d "name=a" https://example.com/form.phpConfirmed by rfc-editor.org
How do I stop it coming back?
- Send the correct Content-Type and read the body with php://input for JSON APIs.
- Keep post_max_size above upload_max_filesize and test uploads at the largest size you allow.
- Point forms at the final https address so no redirect sits in the way.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix