PHP $_POST not working but $_GET works fine

I’m trying to build a simple login system using <form method="post">. Everything works fine on MAMP on my laptop but when I upload the script to the server (Windows) it doesn’t work; it seems that the $_POST array is empty.

I commented out everything but the bare bones and it still doesn’t work.

index.php:

<form id="login-form" method="POST" action="_scripts/check_login.php">
Email Address
<input name="login-email" type="text" id="login-email">
Password
<input name="login-password" type="text" id="login-password">
<input type="submit" name="Submit" id="login-button" value="Login">
</form>

_scripts/check_login.php: (I’ve removed everything except some var_dumps for debugging)

var_dump($_POST);

$loginEmail = trim($_POST['login-email']);
echo '<br>';
$loginPassword = ($_POST['login-password']);
var_dump($loginEmail);
echo '<br>';
var_dump($loginPassword);

When I submit the form, no matter what I put in the text fields, I see this:

array(0) { }
string(0) ""
NULL

If I change all the instances of “post” to “get” in the above two files, everything works fine. But I don’t want to use get. ($_REQUEST doesn’t work either if I submit the form using method=”post”).

NB this all works fine on localhost, but not on the server (which is running Windows.) So it would seem to be a problem with the server, but I have no idea what. You can see the PHPInfo here: http://brailleapps.org/phpinf0.php

Any ideas?

EDIT: Solved! See below.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

I got it fixed eventually, figure I might as well post what worked here in case someone else has the same problem in future.

Turns out one of these HTTP modules was interfering with POST:

RadCompression
RadUploadModule

With these modules turned off, POST worked fine.

(NB this was on a totally new app where I knew there wasn’t any existing code that might have depended on one of those modules… turning them off may have unintended consequences I’m not aware of, YMMV.)

Solution 2

One possibility is that POST is not an allowed verb on the server:

http://www.iis.net/configreference/system.webserver/security/requestfiltering/verbs

Solution 3

I’ve had the same problem with $_POST being empty/NULL, and after spending 30 minutes searching SO and Google I finally found a solution that worked for me.

Since I don’t know how to change the php.ini file for MAMP I edited my htaccess to include this:

php_value post_max_size 60M
php_value upload_max_filesize 60M

and I can var_dump($_POST) with the submitted input fine now.

Reference link: http://helpfulcoder.blogspot.ca/2011/01/empty-post-array-in-mamp.html

Solution 4

and another thing is if you have ever changed .htaccess to hide the format
Example .php or .html

action="filename.php" instead of this give action="filename"

your problem solved.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply