开发者

Form GET works, Form POST does not

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 do开发者_StackOverflow中文版es 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!


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜