背景
基于Web的联系表单。
问题
$_POST
数组为空。当启用错误时,没有发现任何错误(除了空数组值)。这段代码在某个时间点经过测试并工作正常,然后一直没有被修改,直到我发布这个问题。主机可能进行了升级。
软件
- PHP 5.2.17
- Apache 2.0.63
- SSI
HTML表单
HTML表单如下:
<form method="post" action="contact.php" id="commentForm">
<label for="name">Name</label>
<input type="text" name="name" id="name" maxlength="64" /><br />
<label for="email">Email</label>
<input type="text" name="email" id="email" maxlength="320" /><br />
<label for="message">Message</label>
<textarea name="message" rows="10" cols="40" id="Message"></textarea><br />
<label for="human">40 + 2 =</label>
<input type="text" name="human" id="human" size="10" maxlength="3" /><br />
<p align="center">
<input type="submit" name="submit" value="Send" class="submit-button" />
</p>
</form>
PHP 代码
以下代码在表单提交时被调用:
$reason = 'default';
error_reporting( 0 );
ini_set( 'display_errors', 0 );
ini_set( 'register_globals', 0 );
ini_set( 'allow_url_fopen', 0 );
ini_set( 'expose_php', 0 );
ini_set( 'magic_quotes_gpc', 0 );
function not_contacted() {
global $reason;
// Redirects to computer, name, email, or message.
//
header( 'Location: ../error-'.$reason.'.shtml' );
}
function wms_error_handler($errno, $errstr, $errfile, $errline) {
not_contacted();
return true;
}
function wms_shutdown() {
if( is_null( $e = error_get_last() ) === false ) {
not_contacted();
}
}
set_error_handler( "wms_error_handler" );
register_shutdown_function( 'wms_shutdown' );
$name = trim( stripslashes( $_POST["name"] ) );
日志记录
echo $_SERVER["REQUEST_METHOD"];
等于 GET
print_r( $_GET );
等于 数组 ( )
print_r( $_POST );
等于 数组 ( )
print_r( $_REQUEST );
==
Array ( [__utma] => 181723617.1357984856.1311884601.1313715852.1313720411.12 [__utmz] => 181723617.1313720411.12.10.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=jigo [__utmc] => 181723617 [__utmb] => 181723617.3.10.1313720411 ) `
file_get_contents('php://input')
等于空
问题
- 是什么导致了PHP POST变量的值为空?
- 为什么
POST
方法被转换成了GET
方法?
我认为这可能是php.ini或httpd.conf冲突引起的,但不能确定(因为它是托管域)。
谢谢。
更新
以下测试可行。
test.shtml
<html>
<body>
<form method="post" action="test.php">
<input type="hidden" name="test" value="test" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
test.php
<?
echo $_POST["test"];
?>