thinkphp6 header token头发送和接受
2022-11-24 11:10:29
205
{{single.collect_count}}

客户端

<form action="{:url('index2')}">     <input type="text" name="user" id="user">     <input type="button" id="abc" value="tijiao">    </form><script>$("#abc").click(function(){let admintoken=6666; //可有服务端获取或客户端缓存获取$.ajax({        headers: {            "ADMINTOKEN": admintoken        },        url:"{:url('index2')}",        data: {user:$("#user").val()},        success:function (res) {            console.log(res);        },        error:function(){        }})})</script> 

服务端接受到token 

    public function index2()    {        print_r(Request::header('ADMINTOKEN'));//这个也可以获取// header("ADMINTOKEN:{$token}");可以服务端发送echo $_SERVER['HTTP_ADMINTOKEN'];    }

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}