In a plugin, what's the way in PHP to output a CSRF token? My plugin has a tab in the CP. On that tab is a form. What's the way for PHP to generate a CSRF token that can be output to the form with echo?

EDIT to document the final answer

$token = craft()-&gt;request-&gt;getCsrfToken();
$out .= &lt;&lt;&lt;MYFORM
   &lt;form action="#" method="post"&gt;
      &lt;input type='hidden' name="CRAFT_CSRF_TOKEN" value='$token'&gt;
      ...
   &lt;/form&gt;
MYFORM;
return $out;


And make sure that /craft/config/general.php includes this:

return array(
       'enableCsrfProtection' =&gt; true,
);
Maybe try craft()-&gt;request-&gt;getCsrfToken(), see if that does it?

Edit

Sorry, misunderstood the question, since you are saying your plugin has a CP section then i'm assuming you're actually looking for a twig way to output the CSRF input, not so much a PHP way. To output the CRSF input in your template simply do {{ getCsrfInput() }}