2

EDIT: I used var_dump($_POST) OUTSIDE of the if statement.

I've tried multiple solutions and none have worked, so this is my last attempt at resolving this issue. I have a form written in HTML sending data to a PHP script via POST, and the PHP script for whatever reason is only reading $_POST as empty.

Here is my PHP code:

if (isset($_POST['login'])) {
    die('test');
}

Here is my HTML form:

<form action="api/login.php" method="post">
    <input type="text" name="login-email" placeholder="Email">
    <input type="password" name="login-password" placeholder="Password">
    <input type="checkbox" name="login-remember-me" checked>
    <button name="login" type="submit">Login</button>
</form>

var_dump($_POST); returns:

array(0) { }

file_get_contents('php://input'); returns:

login-email=user%40email.com&login-password=123123&login-remember-me=on&login=

Like I said, I have tried every solution I've come across after Googling this issue dozens of times. I am using PHP 5.5.32 NTS on Windows 10 Enterprise x64 with IntelliJ IDEA 15.0.4.

EDIT: Doing var_dump($GLOBALS), my input stayed within ["HTTP_RAW_POST_DATA"], didn't end up anywhere else. I have also tried using PHP 5.6.19 NTS instead of 5.5.32, which still did not fix this issue.

3
  • 1
    You can also dump $GLOBALS like so: var_dump($GLOBALS); to see where your input ended up. Commented Mar 7, 2016 at 0:24
  • 1
    This might sound stupid, but you may not be looking at api/login.php but a file with the same name in a different location...? try changing some text on the file you're editing now (and think is the right one), and see if it actually displays... Commented Mar 7, 2016 at 0:27
  • 1
    @JohnVegas check php.ini post_max_size value and ensure it is set to a valid value? i.e. 8M vs 8MB Commented Mar 7, 2016 at 0:59

2 Answers 2

1

I have noticed that you don't have value in you submit button. Try putting value on it. That's why your PHP code is always not going inside the if statement because the $_POST['login'] is not set.

As per your posting:

login-email=user%40email.com&login-password=123123&login-remember-me=on&login=

So in your PHP code:

if (isset($_POST['login'])) { //there is no value on $_POST['login] so it skips the statement.
    var_dump($_POST);
}

But if you put a value on it like the sample bellow:

<form action="api/login.php" method="post">
    <input type="text" name="login-email" placeholder="Email">
    <input type="password" name="login-password" placeholder="Password">
    <input type="checkbox" name="login-remember-me" checked>
    <button name="login" value="login" type="submit">Login</button>
</form>

It will produce something like this:

login-email=user%40email.com&login-password=123123&login-remember-me=on&login=login

Then you PHP if condition will be satisfied.

if (isset($_POST['login'])) {
    var_dump($_POST);
}

output:

array(4) { ["login-email"]=> string(4) "test" ["login-password"]=> string(4) "test" ["login-remember-me"]=> string(2) "on" ["login"]=> string(5) "login" }

Sign up to request clarification or add additional context in comments.

1 Comment

It was my hypothesis, but I have tested for this yesterday: $_POST['login'] is set also with empty value (Tested on PHP 5.6.18)
0

I have found the cause of the issue, but have not resolved the issue. Luckily, I was not the reason for this issue persisting. Seems like the issue is within IntelliJ IDEA's built-in webserver. Hopefully this helps someone else find a solution.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.