$ _POST与$ _SERVER ['REQUEST_METHOD'] =='POST' [英] $_POST vs. $_SERVER['REQUEST_METHOD'] == 'POST'
问题描述
有人将我的Snipplr提交之一称为废话",因为我使用了if ($_SERVER['REQUEST_METHOD'] == 'POST')
而不是if ($_POST)
Some guy called one of my Snipplr submissions "crap" because I used if ($_SERVER['REQUEST_METHOD'] == 'POST')
instead of if ($_POST)
检查请求方法对我来说似乎更正确,因为那是我真正想要做的.两者之间在操作上有区别吗?还是仅仅是代码清晰性问题?
Checking the request method seems more correct to me because that's what I really want to do. Is there some operational difference between the two or is this just a code clarity issue?
推荐答案
好吧,他们确实做的不一样.
Well, they don't do the same thing, really.
$_SERVER['REQUEST_METHOD']
包含请求方法(惊奇).
$_SERVER['REQUEST_METHOD']
contains the request method (surprise).
$_POST
包含任何帖子数据.
POST请求可能不包含POST数据.
It's possible for a POST request to contain no POST data.
我检查了请求方法-实际上,我从未想过要测试$_POST
数组.不过,我检查了必填字段.因此,空的发布请求会给用户带来很多错误消息-这对我来说很有意义.
I check the request method — I actually never thought about testing the $_POST
array. I check the required post fields, though. So an empty post request would give the user a lot of error messages - which makes sense to me.
这篇关于$ _POST与$ _SERVER ['REQUEST_METHOD'] =='POST'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!