空PHP POST变量 [英] Empty PHP POST Variables
问题描述
背景
基于Web的联系表格。
问题
的 $ _ POST
数组为空。当启用了错误,没有任何错误(除非空数组值)被发现。在code进行了测试,在一个点上工作,然后原封不动,直到我张贴了这个问题。主机可能执行了升级。
软件
- PHP 5.2.17
- 的Apache 2.0.63
- SSI
HTML表单
HTML表单如下:
<形式方法=邮报行动=contact.phpID =commentForm>
<标签=名与GT;名称和LT; /标签>
<输入类型=文本名称=名字ID =名称MAXLENGTH =64/>< BR /> <标签=电子邮件>电子邮件和LT; /标签>
<输入类型=文本名称=电子邮件ID =电子邮件MAXLENGTH =320/>< BR /> <标签=消息>消息< /标签>
< textarea的名称=消息行=10COLS =40ID =消息>< / textarea的>< BR /> <标签=人→40 + 2 =< /标签>
<输入类型=文本名称=人的id =人大小=10MAXLENGTH =3/>< BR /> < p ALIGN =中心>
<输入类型=提交名称=提交值=发送级=提交键/>
&所述; / P>
< /表及GT;
PHP code
以下code是当表单提交名为:
$原因=默认;(0)使用error_reporting;
的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);功能not_contacted(){
全球$理由; //重定向到计算机,姓名,电子邮件或消息。
//
标题(位置:../error-'.$reason.'.shtml');
}功能wms_error_handler($错误号,$ errstr,$ ERRFILE,$ errline){
not_contacted();
返回true;
}功能wms_shutdown(){
如果(is_null($ E = error_get_last())=== FALSE){
not_contacted();
}
}的set_error_han dler(wms_error_handler);
register_shutdown_function('wms_shutdown');$名=修剪(的stripslashes($ _ POST [名称]));
登录
回声$ _ SERVER [REQUEST_METHOD];
== GET
的print_r($ _ GET);
== 阵列()
的print_r($ _ POST);
== 阵列()
的print_r($ _ REQUEST);
==
阵列([__utma] => 181723617.1357984856.1311884601.1313715852.1313720411.12 [__utmz] => 181723617.1313720411.12.10.utmcsr =谷歌| utmccn =(有机)| utmcmd =有机| utmctr = jigo [__utmc] => 181723617 [__utmb] => 181723617.3.10.1313720411)`
的file_get_contents('PHP://输入')
==空缺
问题
- 什么引起的PHP POST变量值是空的?
- 为什么被transmogrified成
GET
方法POST
方法?
我认为这是一个php.ini或httpd.conf文件冲突,但不能肯定(它是一个托管域)。
感谢您。
更新
下面的测试工作。
的 test.shtml中的
< HTML和GT;
<身体GT;
<形式方法=邮报行动=test.php的>
<输入类型=隐藏名称=测试值=测试/>
<输入类型=提交名称=提交值=提交/>
< /表及GT;
< /身体GT;
< / HTML>
的 test.php的的
&LT ;?
回声$ _ POST [测试];
?>
解决方案
删除从的.htaccess
文件中的以下行:
重写规则^(。*)$ http://www.whitemagicsoftware.com/$1 [R = 301,L]
当你看到在Firebug净查看选项卡,会发生什么?是否有JavaScript的参与?是否有正在开始发挥作用的任何重写规则?似乎并不像一个PHP问题。
Background
Web-based contact form.
Problem
The $_POST
array is empty. When errors are enabled, no errors (except empty array values) are found. The code was tested and working at one point, then left untouched until I posted this question. The host might have performed an upgrade.
Software
- PHP 5.2.17
- Apache 2.0.63
- SSI
HTML Form
The HTML form is as follows:
<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 Code
The following code is called when the form is submitted:
$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"] ) );
Logging
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')
== Empty
Questions
- What could be causing the PHP POST variable values to be empty?
- Why is the
POST
method being transmogrified into aGET
method?
I think it is a php.ini or httpd.conf conflict, but cannot be sure (it is a hosted domain).
Thank you.
Update
The following test works.
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"];
?>
Solution
Removed the following line from the .htaccess
file:
RewriteRule ^(.*)$ http://www.whitemagicsoftware.com/$1 [R=301,L]
What happens when you look at the net view tab in firebug? Is there javascript involved? Are there any rewrite rules that are coming into play? Doesn't seem like a php issue.
这篇关于空PHP POST变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!