【发布时间】:2011-10-30 06:56:43
【问题描述】:
背景
基于网络的联系表格。
问题
$_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 ); == Array ( )
print_r( $_POST ); == Array ( )
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"];
?>
解决方案
从.htaccess 文件中删除了以下行:
RewriteRule ^(.*)$ http://www.whitemagicsoftware.com/$1 [R=301,L]
【问题讨论】: