1

I'm working on a website using XAMPP and for some unfathomable reason, $_POST is always empty, no matter what I try.

<form id="reg-form" method="post" action="check.php" enctype="application/x-www-form-urlencoded">
    <label for="user" form="reg-form">Username: </label>
    <input type="text" id="user" name="user" title="Username">
    <br />
    <label for="pass" form="reg-form">Password: </label>
    <input type="password" id="pass" name="pass" title="Password">
    <br />
    <input type="submit" id="submit" title="Submit" value="Submit" form="reg-form">
</form>

And here's check.php:

<?php
if(empty($_SERVER['CONTENT_TYPE'])){

    $type = "application/x-www-form-urlencoded";

    $_SERVER['CONTENT_TYPE'] = $type;

}
var_dump($_POST);
print_r($_POST);
print_r($_GET);
$data = file_get_contents('php://input');
echo($data);

?>

And the output: array(0) { } Array ( ) Array ( ) user=test&pass=test

If I change the method to GET, the get array gets populated without problems.

I've checked php.ini, post is enabled, I have GCPS in variable_order, post_max_size is 8M, but I tried changing it around, didn't help.

I'm at my wit's end and no amount of googling seems to help. Am I overlooking something really simple?

MousE0910
  • 77
  • 4
  • 1
    Take a look at http://stackoverflow.com/questions/1282909/php-post-array-empty-upon-form-submission – Matt Jan 16 '16 at 23:12
  • 1
    Try removing the `enctype`and remove `form` from the submit button – Matt Jan 16 '16 at 23:13
  • I've read over that thread before and nothing helped. `enctype` and `form` I added later in testing, it doesn't work without them either. The Json workaround returns NULL in my $_POST. – MousE0910 Jan 17 '16 at 00:28
  • 1
    You should check your php.ini for `enable_post_data_reading` being set to `false`. If it's set to `false`, `$_POST` is never populated... – Kevin Kopf Jan 17 '16 at 02:00
  • I already checked that and it's ok. I'm fairly sure my php.ini file is correct, at least from what I googled and checked here on Stack Overflow. – MousE0910 Jan 17 '16 at 03:03
  • 1
    @MousE0910 more guesses. 1. Check if `variables_order` is set correctly and that it has `P` in it. 2. What about `post_max_size`? 3. Try switching apache `mod_security` off. If nothing helps, we'll need more info, like your PHP version, your system etc. – Kevin Kopf Jan 17 '16 at 03:33
  • All the variables are in order (see above) and my apache doesn't have mod_security. I just downloaded XAMPP (3.2.2) and I'm using it pretty much just out of the box, no changes to config. PHP is 5.6.15. – MousE0910 Jan 17 '16 at 03:37
  • 1
    @MousE0910 are you using windows or *nix? Are you running suhosin? (don't know if it's shipped with xampp). If so, switch it off: `suhosin.simulation = Off` in `php.ini` – Kevin Kopf Jan 17 '16 at 03:43
  • Windows. No suhosin. – MousE0910 Jan 17 '16 at 03:59

1 Answers1

0

UPDATE I figured it out. I was using phpStorm and it wasn't properly configured to use XAMPP, using its own server-thing instead. Once I configured it properly, suddenly, post is working as intended. Lesson to learn: Always read documentation properly before using IDEs.

robkriegerflow
  • 716
  • 5
  • 13
MousE0910
  • 77
  • 4