空PHP POST变量

jdg4fx2g  于 2022-10-30  发布在  PHP
关注(0)|答案(2)|浏览(181)

背景
基于Web的联系表单。

问题

$_POST数组是空的。当启用错误时,没有发现任何错误(空数组值除外)。代码经过测试,在某个点上工作,然后保持不变,直到我发布了这个问题。主机可能执行了升级。

软件

  • 操作系统
  • Apache2.0.63
  • 系统集成

HTML表单

HTML表单如下所示:

  1. <form method="post" action="contact.php" id="commentForm">
  2. <label for="name">Name</label>
  3. <input type="text" name="name" id="name" maxlength="64" /><br />
  4. <label for="email">Email</label>
  5. <input type="text" name="email" id="email" maxlength="320" /><br />
  6. <label for="message">Message</label>
  7. <textarea name="message" rows="10" cols="40" id="Message"></textarea><br />
  8. <label for="human">40 + 2 =</label>
  9. <input type="text" name="human" id="human" size="10" maxlength="3" /><br />
  10. <p align="center">
  11. <input type="submit" name="submit" value="Send" class="submit-button" />
  12. </p>
  13. </form>

PHP代码

提交表单时将调用以下代码:

  1. $reason = 'default';
  2. error_reporting( 0 );
  3. ini_set( 'display_errors', 0 );
  4. ini_set( 'register_globals', 0 );
  5. ini_set( 'allow_url_fopen', 0 );
  6. ini_set( 'expose_php', 0 );
  7. ini_set( 'magic_quotes_gpc', 0 );
  8. function not_contacted() {
  9. global $reason;
  10. // Redirects to computer, name, email, or message.
  11. //
  12. header( 'Location: ../error-'.$reason.'.shtml' );
  13. }
  14. function wms_error_handler($errno, $errstr, $errfile, $errline) {
  15. not_contacted();
  16. return true;
  17. }
  18. function wms_shutdown() {
  19. if( is_null( $e = error_get_last() ) === false ) {
  20. not_contacted();
  21. }
  22. }
  23. set_error_handler( "wms_error_handler" );
  24. register_shutdown_function( 'wms_shutdown' );
  25. $name = trim( stripslashes( $_POST["name"] ) );

记录
echo $_SERVER["REQUEST_METHOD"]; == GET
print_r( $_GET ); == Array ( )
print_r( $_POST ); == Array ( )
print_r( $_REQUEST ); =

  1. 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') ==空

个问题

1.是什么原因导致PHP POST变量值为空?
1.为什么要将POST方法转换为GET方法?
我认为这是一个php.ini或httpd.conf冲突,但不能肯定(这是一个托管域)。

  • 谢谢-谢谢

更新

以下测试有效。

  • 测试.shtml*
  1. <html>
  2. <body>
  3. <form method="post" action="test.php">
  4. <input type="hidden" name="test" value="test" />
  5. <input type="submit" name="submit" value="submit" />
  6. </form>
  7. </body>
  8. </html>
  • 测试.php*
  1. <?
  2. echo $_POST["test"];
  3. ?>
pkln4tw6

pkln4tw61#

我也有类似的问题。
问题是数据已发送到http url,但存在到https版本url的重定向。在重定向过程中,$_POST中的数据丢失。
我希望这能帮助其他人

kgsdhlau

kgsdhlau2#

.htaccess文件中删除以下行:

  1. RewriteRule ^(.*)$ http://www.whitemagicsoftware.com/$1 [R=301,L]

相关问题