Skip to content

Instantly share code, notes, and snippets.

@jsanbae
Created January 3, 2020 16:10
Show Gist options
  • Save jsanbae/09ddad855c3cc9b53182b428d26c6a05 to your computer and use it in GitHub Desktop.
Save jsanbae/09ddad855c3cc9b53182b428d26c6a05 to your computer and use it in GitHub Desktop.
<?php
/**
* A view Helper from CSRF
*
* Prints the Token
*
* @author Javier Sanchez
*/
class Zend_View_Helper_Csrf extends Zend_View_Helper_Abstract {
public function CsrfViewHelper()
{
return $this;
}
public function getToken()
{
$session = new Zend_Session_Namespace('CsrfProtect');
if (!isset($session->key)) {
throw new RuntimeException('Token non-existent');
} else {
return $session->key;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment