Handling Fake POST for getRequest()->isPost() in Magento 1.8

magento-1.8

how to create a fake POST to bypass

    $_POST = array('blahblah'=>1);
    $_REQUEST = array('blahblah'=>1);

    if($this->getRequest()->isPost())
    {
        echo 'horray bypassed';
    }else
    { 
           echo ':(';
    }

and is not working

here the answer:

$_SERVER['REQUEST_METHOD'] = 'POST';
/* by pass */

$this->getRequest()->isPost()

Best Answer

Have a look at Zend_Controller_Request_Http were the isPost() method is found and you will see the method is as follows:

public function isPost()
{
    if ('POST' == $this->getMethod()) {
        return true;
    }

    return false;
}

and getMethod() is:

public function getMethod()
{
    return $this->getServer('REQUEST_METHOD');
}

So isPost() doesn't look for the existence of data in the $_POST array to detect a POST request, it looks at the $_SERVER variable REQUEST_METHOD.

Related Topic