Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...