I was following the example today from https://forum.phalcon.io/discussion/4737/csrf-validation-does-not-work-on-remote-server and can someone explain what this error mean? It happened when I call $tokenKey = $security->getTokenKey();
and $token = $security->getToken();
in my ControllerBase.
Here is my Security.php
:
<?php
use \Phalcon\DI;
class Security extends \Phalcon\Security
{
public function getTokenKey($numberBytes = 13)
{
$key = '$PHALCON/CSRF/KEY$';
$tokenKey = \Phalcon\DI::getDefault()->getShared('session')->get($key);
if ($tokenKey)
{
return $tokenKey;
}
return parent::getTokenKey($numberBytes);
}
public function getToken($numberBytes = 32)
{
$key = '$PHALCON/CSRF$';
$token = \Phalcon\DI::getDefault()->getShared('session')->get($key);
if ($token)
{
return $token;
}
return parent::getToken($numberBytes);
}
public function changeToken($numberBytes = 32)
{
return parent::getToken($numberBytes);
}
}
And this is from my index.php
:
// Security
$di->setShared('security', function() {
$security = new Security();
return $security;
});
// Session
$di->setShared('session', function() {
$session = new \Phalcon\Session\Adapter\Files();
$session->start();
return $session;
});
The reason I am setting this up is because the checktoken() is invalidating me when I am following the way the documentation handles csrf token.