首页 > Web开发 > 详细

thinkphp5 请求判断类型

时间:2020-10-02 13:40:24      阅读:32      评论:0      收藏:0      [点我收藏+]

获取请求类型

在很多情况下面,我们需要判断当前操作的请求类型是GET、POST、PUT、DELETE或者HEAD,一方面可以针对请求类型作出不同的逻辑处理,另外一方面有些情况下面需要验证安全性,过滤不安全的请求。

ThinkPHP5.0 取消了用于判断请求类型的系统常量(如IS_GET,IS_POST等),统一采用 think\Request类 处理请求类型。

1,是否为 GET 请求

if (Request::instance()->isGet()) echo "当前为 GET 请求";

2,是否为 POST 请求
if (Request::instance()->isPost()) echo "当前为 POST 请求";
3,是否为 PUT 请求
if (Request::instance()->isPut()) echo "当前为 PUT 请求";
4,是否为 DELETE 请求
if (Request::instance()->isDelete()) echo "当前为 DELETE 请求";
5, 是否为 Ajax 请求
if (Request::instance()->isAjax()) echo "当前为 Ajax 请求";
6, 是否为 Pjax 请求
if (Request::instance()->isPjax()) echo "当前为 Pjax 请求";
// 是否为手机访问
if (Request::instance()->isMobile()) echo "当前为手机访问";
7,是否为 HEAD 请求
if (Request::instance()->isHead()) echo "当前为 HEAD 请求";
8,是否为 Patch 请求
if (Request::instance()->isPatch()) echo "当前为 PATCH 请求";
9, 是否为 OPTIONS 请求
if (Request::instance()->isOptions()) echo "当前为 OPTIONS 请求";

文章来自 http://www.96net.com.cn/

thinkphp5 请求判断类型

原文:https://www.cnblogs.com/96net/p/13760928.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!