I've used the CsrfComponent, and I even implement the csrfToken by myself but neither of the solutions seem to work.
Here is my code:
view:
<?php $session->write('sCsrfToken', sha1(microtime())); ?>
<?= $this->Form->create(false)?>
<!-- Some input fields -->
<?= $this->Form->input('pCsrfToken', ['type' => 'hidden',
'value' => h($session->read('sCsrfToken'))]) ?>
<?= $this->Form->button('Submit') ?>
<?= $this->form->end();?>
controller:
if($this->request->is('post')){
$sessionToken = $session->read('sCsrfToken');
$postToken = $this->request->data('pCsrfToken');
if(empty($sessionToken) || $postToken != $sessionToken) {
throw new Exception();
}
else {
$session->write('sCsrfToken', sha1(microtime()));
//DB INSERT, SEND MAIL...
}
Thank you