php 找出PHP中的HTTP方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1538065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find out HTTP method in PHP
提问by eWolf
How can I find out which method (usually GET or POST) is used for the current request?
如何找出当前请求使用了哪种方法(通常是 GET 或 POST)?
回答by Dominic Rodger
回答by eWolf
While checking
检查时
$_SERVER['REQUEST_METHOD']
seems the obvious choice, since some of the people are advocating safe superglobals alternatives (Is using superglobals directly good or bad in PHP?and similar questions), one may instead use automatic sanitizing
似乎是显而易见的选择,因为有些人提倡安全的超全局替代方案(在 PHP 中直接使用超全局是好是坏?以及类似的问题),人们可以改为使用自动清理
filter_input( \INPUT_SERVER, 'REQUEST_METHOD', \FILTER_SANITIZE_SPECIAL_CHARS )
(you might of course use other filter, eg. FILTER_SANITIZE_STRING- see herefor a full list).
(您当然可以使用其他过滤器,例如FILTER_SANITIZE_STRING- 请参阅此处获取完整列表)。
Obviously, in the regular (GET/POST) case there ain't anything to sanitize, but a good habit is still a good habit IMO.
显然,在常规 ( GET/ POST) 情况下,没有什么需要消毒的,但好习惯仍然是 IMO 的好习惯。
http://php.net/manual/en/reserved.variables.server.php
http://php.net/manual/en/reserved.variables.server.php

