PHP $_POST not working but $_GET works fine(PHP $_POST 不工作,但 $_GET 工作正常)
问题描述
我正在尝试使用 <form method="post">
构建一个简单的登录系统.在我的笔记本电脑上的 MAMP 上一切正常,但是当我将脚本上传到服务器 (Windows) 时,它不起作用;似乎 $_POST 数组是空的.
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:(除了一些用于调试的 var_dumps 之外,我已经删除了所有内容)
_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
如果我将上述两个文件中的所有post"实例更改为get",则一切正常.但我不想使用get.(如果我使用 method="post" 提交表单,$_REQUEST 也不起作用.
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").
注意,这一切在本地主机上都可以正常工作,但在服务器(运行 Windows 的服务器)上却没有.所以这似乎是服务器的问题,但我不知道是什么.您可以在此处查看 PHPInfo:http://brailleapps.org/phpinf0.php
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
有什么想法吗?
解决了!见下文.
推荐答案
我最终解决了这个问题,我想我不妨发布一下这里有用的内容,以防其他人将来遇到同样的问题.
I got it fixed eventually, figure I might as well post what worked here in case someone else has the same problem in future.
结果是这些 HTTP 模块之一干扰了 POST:
Turns out one of these HTTP modules was interfering with POST:
RadCompression
RadUploadModule
RadCompression
RadUploadModule
关闭这些模块后,POST 工作正常.
With these modules turned off, POST worked fine.
(注意这是在一个全新的应用程序上,我知道没有任何现有代码可能依赖于这些模块之一......关闭它们可能会产生我不知道的意外后果,YMMV.)
(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.)
这篇关于PHP $_POST 不工作,但 $_GET 工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!