【发布时间】:2016-01-16 23:08:49
【问题描述】:
我正在使用 XAMPP 开发一个网站,但出于某种深不可测的原因,无论我尝试什么,$_POST 总是为空。
<form id="reg-form" method="post" action="check.php" enctype="application/x-www-form-urlencoded">
<label for="user" form="reg-form">Username: </label>
<input type="text" id="user" name="user" title="Username">
<br />
<label for="pass" form="reg-form">Password: </label>
<input type="password" id="pass" name="pass" title="Password">
<br />
<input type="submit" id="submit" title="Submit" value="Submit" form="reg-form">
</form>
这里是 check.php:
<?php
if(empty($_SERVER['CONTENT_TYPE'])){
$type = "application/x-www-form-urlencoded";
$_SERVER['CONTENT_TYPE'] = $type;
}
var_dump($_POST);
print_r($_POST);
print_r($_GET);
$data = file_get_contents('php://input');
echo($data);
?>
然后输出: 数组(0) { } 数组( ) 数组( ) user=test&pass=test
如果我将方法更改为 GET,则 get 数组会毫无问题地填充。
我检查了 php.ini,post 已启用,我在 variable_order 中有 GCPS,post_max_size 为 8M,但我尝试更改它,但没有帮助。
我已经束手无策了,再多的谷歌搜索似乎也无济于事。我是否忽略了一些非常简单的事情?
【问题讨论】:
-
尝试删除
enctype并从提交按钮中删除form -
您应该检查您的 php.ini 是否将
enable_post_data_reading设置为false。如果设置为false,则永远不会填充$_POST... -
@MousE0910 更多猜测。 1. 检查
variables_order是否设置正确,是否包含P。 2、post_max_size呢? 3. 尝试关闭 apachemod_security。如果没有任何帮助,我们将需要更多信息,例如您的 PHP 版本、系统等。 -
@MousE0910 您使用的是 windows 还是 *nix?你在运行 suhosin 吗? (不知道它是否与xampp一起提供)。如果是这样,请将其关闭:
suhosin.simulation = Offinphp.ini