Form GET works, Form POST does not

2019-03-06 14:13发布

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

FORM:

<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>

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...)

Things to know:

  • .htaccess handles the .php of the filename (action), it also redirects everything to index.php if the file does not physically exist.
  • other forms on the site work just fine with POST
  • the form works fine on my local machine
  • Firebug shows 302 Temporarily Moved when using POST

.htaccess file added per request:

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

Any help is appreciated!

3条回答
在下西门庆
2楼-- · 2019-03-06 14:23

This is an edge case answer that may benefit a future user researching this topic.

In my case the solution was to fix a mis-configuration I had created in my local php.ini file. I had changed my settings to be more liberal for the sake of running Imagick image processing scripts during development work.

In an attempt to increase the max_post_size from its default value of 8M, I had changed the setting to 40. The problem was the lack of explicitly stating the units that "40" referred to. When not specified, php.ini uses BYTES as the units. I added the "M" unit suffix to "40" and $_POST actions began working as expected.

For future reference, the unit suffixes can be either "K", "M", or "G", without the quotes of course, or, for bytes, absent. You can read about these units in the PHP Manual here:

https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-03-06 14:38

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

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.

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

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.

查看更多
神经病院院长
4楼-- · 2019-03-06 14:45

If "/login" doesn't exist, and htaccess redirects (not re-writes the url) then all POST data are lost. GET data are preserved because they're part of the URL.

查看更多
登录 后发表回答