表单 GET 有效,表单 POST 无效

2022-01-04 00:00:00 post forms get php .htaccess

我有一个简单的表单,当 method="GET" 时它的行为符合预期,但是当 method="POST" 时,它不会.

I have a simple form that behaves as expected when method="GET", but when method="POST", it does not.

表格:

<form action="/login" method="POST">
<input type="text" name="user" maxlength="30" value="">
<input type="password" name="pass" maxlength="30" value="">
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login" /> 
</form>

如果我将变量回显到屏幕(var_dump( $_POST )var_dump( $_GET )),当 method="POST" 时,我得到一个空大批.当 method="GET" 时,我得到一个具有适当名称/值对(用户、密码、子登录...)的数组

If I echo the variables to the screen (var_dump( $_POST ) or var_dump( $_GET )), when method="POST", I get an empty array. When method="GET" I get an array with the appropriate name/value pairs (user, pass, sublogin...)

注意事项:

  • .htaccess 处理文件名的 .php(动作),如果文件实际上不存在,它还会将所有内容重定向到 index.php.
  • 网站上的其他表单与 POST 配合使用也很好
  • 表单在我的本地机器上运行良好
  • Firebug 在使用 POST 时显示 302 Temporously Moved

每个请求添加的.htaccess 文件:

.htaccess file added per request:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .$ index.php

感谢任何帮助!

推荐答案

这个问题与我的想法并不接近.

The problem wasn't even close to my line of thought.

一个在处理后设置销毁 $_POST 数组的类行为不当,但无论如何都在销毁我的 $_POST 数组.仅在 PHP 5.3 机器上发生(警告导致类行为异常),服务器运行 5.2.

A class that sets destroys the $_POST array after processing was misbehaving, but was destroying my $_POST array anyway. Only happens on machines with PHP 5.3 (a warning was causing the class to misbehave), server was running 5.2.

谢谢 Briedis 的帮助.对不起,我带你去追鹅了!

Thank you, Briedis for trying to help. Sorry I led you on a goose chase!

当然,解决方案是编写一种更好的方法来处理该类中的警告,并且不允许 $_POST 数组被破坏.

The solution, of course, was to write a better way of handling warnings in that class and not allowing the $_POST array to get destroyed.

相关文章