1

PHP 5.4.17

I have a simple html form that looks something like this:

index.html

<form method="POST" action="/addnewaccount.php">
    <input type="text" name="firstname" />
    <button type="submit">Submit</button>
</form>

addnewaccount.php

<?php
var_dump($_POST); // array(0) {}
var_dump($_REQUEST); // array(0) {}
var_dump(file_get_contents('php://input')); //string(0) ""
var_dump($HTTP_RAW_POST_DATA); // NULL

When this form gets submitted, php will not populate the $_POST or $_REQUEST variables. They are just empty arrays.

I have checked the following in my php.ini file:

enable_post_data_reading = On
post_max_size = 10M
variables_order = "GPCS"
request_order = "GP"

If I change the form's enctype to "multipart/form-data", the $_POST and $_REQUEST variables are populated, so I feel that the issue is with the default enctype of "x-www-form-urlencoded", but I can't figure out how to get things to work with the default.

4
  • Is var_dump(file_get_contents("php://input")); outputting any content? If no then most I would check if there is no special configuration in your webserver which limits this. Also: do you maybe have suhosin installed? Check this by printing out your phpinfo(); (better than checking php.ini in case you missed somewhere loading of additional modules). Jan 9, 2020 at 0:29
  • Did you check the answers of this question: php $_POST array empty upon form submission your case could be one of them. Jan 9, 2020 at 0:35
  • Thank you @BartoszPachołek. Because I am not posting JSON, php://input is just an empty string. Jan 9, 2020 at 16:25
  • Thank you @Accountantم, I have reviewed the answers in that other StackOverflow question and none of them have solved the problem. Jan 9, 2020 at 16:25

1 Answer 1

0

I was able to solve this problem. I discovered that it was an interaction of our Node proxy and php.

In our Node code, we were using the 'body-parser' npm package. We had a line where we were using the middleware for form-data like this:

app.use(bodyParser.urlencoded({extended: true}));

That middleware converted the form data to JSON before the request was proxied which prevented PHP from getting the data.

Hopefully this helps someone who might have a similar situation in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.