thinkphp5.0.19 表单令牌

助手函数token() [F:phpStudyWWWcsweb hinkphphelper.php]

request类token()方法 [F:phpStudyWWWcsweb hinkphplibrary hinkRequest.php]

token生成函数可以自定义:

定义全局函数:

1 function token_fun($p){
2     return "token_".$p;
3 }

调用:

 1 <?php
 2 namespace appindexcontroller;
 3 class Test extends BasicAdmin
 4 {
 5     public function index()
 6     {
 7         var_dump(request()->token('__token__', 'token_fun'));
 8         //return $this->_view_fetch("/test/index");
 9     }
10 }

显示:

 ajax请求时调用token()会将token附加到response header中:

原文地址:https://www.cnblogs.com/natian-ws/p/9511113.html