tp5开发接口:接口参数过滤验证规则

本文探讨了在TP5框架下,如何基于安全设计为接口添加参数过滤和验证规则,确保接口调用的安全性和数据准确性。
摘要由CSDN通过智能技术生成

1.上文参考      接口安全设计-上

2. 安全设计基础上,增加参数过滤验证规则

 

<?php

namespace app\api\controller;

use think\Request;
use think\Controller;

// 参数过滤,需要的核心类
use think\Validate;

class Common extends Controller
{
	protected $request;  //用来处理参数

	protected $validater;  // 用来验证数据/参数
	protected $params;  // 过滤后符合要求的参数
	// 定义验证规则
	protected $rules = array(
		'User' => array(
			'login'=>array(
				'user_name'=>['require','chsDash','max'=>20],
				'user_pwd'=>'require|length:32'
			),
			'reqister'=>array(),
		),
	);

	// 获取 ;$rules['User']['login']

	protected function _initialize(){
		parent::_initialize();
		$this -> request = Request::instance();
		// 判断传过来的时间戳是否超时
		$this -> check_time($this->request
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值