ThinkPHP 判断请求类型
用 ThinkPHP6 判断当前操作的请求类型
一、针对请求类型作出不同的逻辑处理;
二、验证安全性,过滤不安全的请求;
<?php namespace app\controller; use think\facade\Request; class Ceshi { public function index(){ if(request()->isAjax()){ return '是 Ajax 请求'; }else{ return '不是 Ajax 请求'; } } } // 请求队形 Request 类提供了下类方法来判断当前请求类型 // 获取当前请求类型 method() // 判断是否GET请求 isGet() // 判断是否POST请求 isPost() // 判断是否PUT请求 isPut() // 判断是否DELETE请求 isDelete() // 判断是否AJAX请求 isAjax() // 判断是否PJAX请求 isPjax() // 判断是否JSON请求 isJson() // 判断是否手机访问 isMobile() // 判断是否HEAD请求 isHead() // 判断是否PATCH请求 isPatch() // 判断是否OPTIONS请求 isOptions() // 判断是否为CLI执行 isCli() // 判断是否为CGI模式 isCgi()