How to use Zend_Form_Element_Hash?

Then I try to use Zend_Form_Element_Hash, it regenerates the hash of each request.

In my code:

 // form
 $this->addElement('hash', 'hihacker', array('salt' => 'thesal'));

Then I flush $ _SESSION. I see a new value that reloads every page.

Then I submit a form reporting the error "Token 28a5e0e2a50a3d4afaa654468fd29420" does not match the specified token "a64407cc11376dac1916d2101de90d29", each time a new pair of tokens

+3
source share
3 answers
$form = new Form();
$form->addElement('hash', 'hihacker',
    array('salt' => 'YOUR TOO MUCH SALTY TEXT !!@@'));
if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) {
    // Valid ! you are safe do what ever you want .
} else if (count($form->getErrors('request_token')) > 0) {

    ///get him to the error controller 
    $this->_forward('csrf-forbidden', 'error');
    return;
}

its work is very good for me, but double check the session settings

" Zend_Session_Namespace ( , TTL ). " " , . formHidden . " ZF docs

+5

Zend_Form_Element_Hash . , , , . /.

ajax - , ( )

$- > hash- > initCsrfToken();

$this- > view- > hash = $form- > hash- > getValue();

, ajax, .replaceWith().

, , -, - , Zend. ,

+1

, - script... 1, .

FWIW , ZF. , = 2. ZF, .

0

Source: https://habr.com/ru/post/1721139/


All Articles