我已经检查过这段代码几次。
这是发送 POST 数据的表单:
<form action="/loginwizard" method="post">
<input type="hidden" name="action" value="login">
Email:
<br>
<input type="text" name="email" id="email" size=100>
<br>
Password:
<br>
<input type="password" name="pword" id="pword" size=100>
<br>
<input type="submit" value="Login">
</form>
我的 php 脚本使用:
print_r($_REQUEST);
结果是:
Array()
这是使用:
PHP:版本 5.6.8,
系统:Windows NT XXX-PC 6.1 build 7601(Windows 7 Home Premium Edition Service Pack 1)i586
Apache:Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8
如果它有任何意义,always_populate_raw_post_data 设置为 0
最佳答案
The ODDEST thing about this is if I CHANGE action="/loginwizard" to action="/loginwizard/index.php" The form works great. I have a suspicion this is due to something in the Xampp installation?
这是因为DirectorySlash
指令,默认设置为On
。
它会导致 Apache 向带有尾部斜杠的 URL 发出外部重定向 - 并且浏览器会在该重定向后使用 GET 请求,因此您的 POST 数据会丢失。
关闭该指令可能会产生安全隐患,请参阅手册中的警告 - 但这不是必需的,只需将表单操作指向开头带有斜杠的目录即可:
<form action="/loginwizard/" method="post">
^
然后请求将被传递到该目录的索引文件/脚本(通过 DirectoryIndex
指令),在本例中是 index.php
,但是没有外部重定向,因此您的 POST 数据将出现在 $_REQUEST
或 $_POST
中。如果您只想让此脚本处理通过 POST 请求接收的数据,那么我建议使用后者,更具体地说。否则,GET 和 COOKIE 数据可能会产生干扰,具体取决于 PHP 的 request_order
/variables_order
配置设置值。
关于php - HTML 表单 POST $_REQUEST 数据消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35374898/