I am using ZF’s Zend_Form_Element_Hash to protect my form against CSRF.
The problem however is that the token generated expires too soon. I’m guessing the problem is with the session lifetime, because that is where it is stored.
I use this code to generate it:
$token = new Zend_Form_Element_Hash('tk');
$token->setSalt(md5(uniqid(mt_rand(), TRUE)));
Is there any way I can make the token valid for a longer period of time?
Am I doing it right or there is a better way? I am new to Zend Framework.
There is also a
timeoutproperty within Zend_Form_Element_Hash that serves as a TTL for the CSRF token. By default it is 300 seconds (5 minutes).You can increase this timeout by passing a value for
timeoutas an option.Zend_Form_Element_Hash API Doc