Jaco Roux
Jaco Roux

Reputation: 11

REQUEST_METHOD changed to 'POST_method=POST'

When doing a post from a form, the $_SERVER['REQUEST_METHOD'] is POST_method=POST, when I do a normal get request the value is GET. This was never the case, and changed after I updated my server.

I am almost sure that the value is supposed to be POST

Example:

'REQUEST_METHOD' => 'POST_method=POST',

I am using CakePHP and on deletes where $this->request->onlyAllow('post', 'delete');is set, I get an error of Method not allowed, which I understand, because the method is not POST.

Does anyone know where this is set on the server or in the php config?

Update 1:

If I submit this form:

<form action="/sources/select_categories/10" id="SourceCategorySelectCategoriesForm" method="post" accept-charset="utf-8">
<div style="display:none;"><input type="hidden" name="_method" value="POST"/></div>
<div class="submit"><input  class="btn btn-primary btn-lg" type="submit" value="Select Categories"/></div>
</form>

I get:

'REQUEST_METHOD' => 'POST_method=POST',

and the posted values are:

array(
'_method' => 'POST_method=POST'
)

And if I submit this form:

<form action="/sources/select_categories/10" id="SourceCategorySelectCategoriesForm" method="post" accept-charset="utf-8">
<div style="display:none;"><input type="hidden" name="_method" value="POST"/></div>
    <input type="checkbox" name="data[SourceCategory][category_ids][]"  value="5" id="SourceCategoryCategoryIds"/>
    <input type="checkbox" name="data[SourceCategory][category_ids][]"  value="6" id="SourceCategoryCategoryIds"/>
    <input type="checkbox" name="data[SourceCategory][category_ids][]"  value="4" id="SourceCategoryCategoryIds"/>
    <input type="checkbox" name="data[SourceCategory][category_ids][]"  value="3" id="SourceCategoryCategoryIds"/>
<div class="submit"><input  class="btn btn-primary btn-lg" type="submit" value="Select Categories"/></div></form>

I get:

'REQUEST_METHOD' => 'POST',

But the received values are:

array(
'_method' => 'POST',
'data' => array(
    'SourceCategory' => array(
        'category_ids' => array(
            (int) 0 => '5',
            (int) 1 => '6',
            (int) 2 => '4',
            (int) 3 => '3_method=POST',
            (int) 4 => '5',
            (int) 5 => '6',
            (int) 6 => '4',
            (int) 7 => '3'
        )
    )
)
)

So something weird is going on. When the form is empty of any fields, The Request method changes, and if I have fields, the field values looks all funny.

Any suggestions what could be causing this?

UPDATE 2:

I just tried a form on in it's own php file, bypassing cakephp all together

<form action="test2.php" method="post">
<input type="hidden" name="_method" value="POST"/>
<input type="submit" value="Select Categories"/>
</form>

The $_SERVER["REQUEST_METHOD"] stays "POST", but a print_r($_POST) renders:

Array
(
    [_method] => POST_method=POST
)

So it seems that it must be php or apache that is changing the post variable "_method" and then CakePHP changes the $_SERVER["REQUEST_METHOD"].

This is making me clueless, and I don't know where to start with this. Maybe uninstall php and apache?

Update 3

Form 1

<form action="test2.php" method="post">
<input type="hidden" name="x" value="y"/>
<input type="submit" value="Submit"/>
</form>

Gives

Array
(
    [x] => yx=y
)

Form 2:

<form action="test2.php" method="post">
<input type="hidden" name="x" value="y"/>
<input type="hidden" name="a" value="b"/>
<input type="submit" value="Submit"/>
</form>

Gives:

Array
(
    [x] => y
    [a] => b
)

So if a single hidden value is posted, regardless of the name, it gets changed, if 2 values are posted, it seems to be working fine.

Upvotes: 0

Views: 2354

Answers (2)

Jaco Roux
Jaco Roux

Reputation: 11

I seem to have fixed it, although I still have no idea what caused it.

I un installed PHP

sudo apt-get -y purge php*

Then installed PHP

sudo apt-get install php5

Then all my libs

sudo apt-get install php5-mysql
sudo apt-get install php5-gd
sudo apt-get install php5-xmlrpc
sudo apt-get install php5-curl

And after all that it still works. Not sure if I have forgotten anything, but everything seems to work again.

I would still like to know what php lib caused the variables to be changed.

Thanks for all the input from everyone.

Upvotes: 1

ndm
ndm

Reputation: 60503

The value is being set in CakeRequest::_processPost().

It retreives the value from either the HTTP_X_HTTP_METHOD_OVERRIDE environment variable (which originates from the X-HTTP-Method-Override HTTP header), or from the _method POST field. The latter is automatically defined in an hidden field by the FormHelper class (see FormHelper::create(), FormHelper::postList()).

You'll have to do some debugging, check whether you are sending the mentioned header, look through the HTML source of your form, the _method field should by default only contain POST or PUT. If there's something else in the field then check whether you are maybe passing the method option to the helper methods (though in that case the value should be all uppercase).

Upvotes: 0

Related Questions