Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP $_POST not working but $_GET works fine

Tags:

post

forms

php

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.

like image 424
GMA Avatar asked Mar 13 '13 13:03

GMA


2 Answers

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.)

like image 96
GMA Avatar answered Nov 03 '22 00:11

GMA


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

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

like image 38
Bart Avatar answered Nov 03 '22 00:11

Bart