为什么我应该使用$ _GET和$ _POST而不是$ _REQUEST? [英] Why should I use $_GET and $_POST instead of $_REQUEST?

查看:56
本文介绍了为什么我应该使用$ _GET和$ _POST而不是$ _REQUEST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了$_REQUEST从cookie读取的事实之外,我是否应该出于任何原因使用$_GET$_POST而不是$_REQUEST?这样做的理论和实践原因是什么?

Besides the fact that $_REQUEST reads from cookies, are there any reasons why I should use $_GET and $_POST instead of $_REQUEST? What are theoretical and practical reasons for doing so?

推荐答案

当我只希望用户的某些数据返回某些数据时,我使用$ _REQUEST.

I use $_REQUEST when I just want certain data from the user to return certain data.

当请求有副作用时,切勿使用$ _REQUEST.产生副作用的请求应为POST(出于语义原因,以及由于CSRF的基本要求,一个错误的img标签可能会在用户不知情的情况下击中任何GET端点).

Never use $_REQUEST when the request will have side effects. Requests that produce side effects should be POST (for semantic reasons, and also because of basic CSRF stuff, a false img tag can hit any GET endpoint without a user even knowing).

在GET或POST到页面会产生不同结果时,应使用$ _GET.

$_GET should be used when GETing or POSTing to a page will produce different results.

这篇关于为什么我应该使用$ _GET和$ _POST而不是$ _REQUEST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆