数据库 - Model 前置说明
官方开源项目 抓取代理IP

介绍

@Csrf()注解,主要用于校验Csrf令牌是否有效。

用法

场景:校验Csrf令牌是否有效。
支持:HTTP
注解:@Csrf()

参数:

  • type=""

    • 功能:令牌数据存储的类型
    • 值单位:目前支持4个类型,分别为:getpostrawheader
    • 默认值post
  • name=""

    • 功能:数据字段名称
    • 值单位:字符串
    • 默认值csrf
  • clean=""

    • 功能:校验通过后是否直接清除令牌
    • 值单位false否、true
    • 默认值true
  • tips=""

    • 功能:校验不通过时,输出给回调方法的提示内容
    • 值单位false否、true
    • 默认值:系统编译提示语

使用案例

一个完整的案例如下:

<?php
namespace app\http;
use x\controller\Http;

class Index extends Http
{
	/**
	 * @RequestMapping(route="/index", method="get", title="主页")
	 * @Csrf(type="get", name="token", clean="true", tips="令牌错误")
	*/
	public function index() {
		// Csrf令牌通过 get[token]提交上来
		return $this->fetch('通过校验了');
	}
	/**
	 * @RequestMapping(route="/test", method="get", title="主页")
	*/
	public function test() {
		// 这里生成Token到视图,然后放到表单里提交到index路由
		return $this->fetch(csrf());
	}
}

当校验不通过时,会回调到生命周期\box\lifecycle\csrf_error类中进行处理。

SW-X

企业级 - 高性能 PHP 框架

最后更新:3年前 . 作者-小黄牛

本篇目录