[英]PHP detecting request type (GET, POST, PUT or DELETE) without using $_SERVER['REQUEST_METHOD']
How can I find server request type (GET, POST, PUT or DELETE)
without using $_SERVER['REQUEST_METHOD']
from action page? 如何在不使用操作页面中的
$_SERVER['REQUEST_METHOD']
情况下找到服务器请求类型(GET, POST, PUT or DELETE)
?
I am submitting page from abc.php
form action page is action page. 我从
abc.php
表单操作页面提交页面是操作页面。
I need to print which method used 我需要打印使用哪种方法
Regular if statements 常规if语句
if(!empty($_GET)) {
$request = (!empty($_POST)) ? 'both get and post' : 'get';
} else if(!empty($_POST)) {
$request = 'post';
}
//... You get the picture
Edit: I added a ternary within the get check to solve a problem that Gumbo noted in the comments. 编辑:我在get检查中添加了三元来解决Gumbo在评论中指出的问题。 You can have both GET and POST vars available as you can POST data to a url with get params, ie /forms/addFileToCompany/?companyId=23
您可以同时使用GET和POST变量,因为可以使用get参数将数据发布到url,即/ forms / addFileToCompany /?companyId = 23
And now because I am a complete filth, the most horrible ternary you have ever seen! 现在,因为我是一个完整的污秽,所以您所见过的最可怕的三元! Note this is just for a bit of fun and I really do not recommend using it.
请注意,这只是出于一点乐趣,我真的不建议您使用它。
$request = (!empty($_GET))
? (!empty($_POST))
? 'both post and get'
: 'get'
: (!empty($_POST))
? 'post'
: (/* Keep it going for whatever */ );
There's a tricky way and a not so smart way I believe. 我相信这是一种棘手的方法,而不是那么聪明的方法。 Is to check it manually like for example:
是手动检查它,例如:
if( isset($_GET) ) $request_type = 'GET Method';
elseif( isset($_POST) ) $request_type = 'POST Method';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.