Skip to content

Instantly share code, notes, and snippets.

@sfengyuan
Last active January 13, 2016 08:07
Show Gist options
  • Save sfengyuan/8deec78f9a138656adca to your computer and use it in GitHub Desktop.
Save sfengyuan/8deec78f9a138656adca to your computer and use it in GitHub Desktop.
Codeigniter csrf token helper
// In codeigniter, form_open() can automatic output a csrf token field.
// But, I prefer use the html form tag.
// This function can manually insert a token to form elements.
function csrf_token()
{
$CI = & get_instance();
$hidden[$CI->security->get_csrf_token_name()]= $CI->security->get_csrf_hash();
$form_token = sprintf("<div style=\"display:none\">%s</div>", form_hidden($hidden));
echo $form_token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment