本文翻译自:Check whether a request is GET or POST [duplicate]
Possible Duplicate: 可能重复: PHP detecting request type (GET, POST, PUT or DELETE) PHP检测请求类型(GET,POST,PUT或DELETE)
This should be an easy one. 这应该很简单。
I have a script, and in the script I want to determine whether the request arrive via GET or POST method. 我有一个脚本,在脚本中我想确定请求是通过GET还是POST方法到达的。
What is the correct way to do it? 这样做的正确方法是什么?
I am thinking of using something like this 我正在考虑使用这样的东西
if (isset($_POST)) { // do post } else { // do get }But deep in my heart I don't feel this is the right way. 但在我内心深处,我觉得这不是正确的方法。 Any idea? 任何的想法?
参考:https://stackoom.com/question/5kxP/检查请求是GET还是POST-重复
使用$_SERVER['REQUEST_METHOD'] 。
Better use $_SERVER['REQUEST_METHOD'] : 最好使用$_SERVER['REQUEST_METHOD'] :
if ($_SERVER['REQUEST_METHOD'] === 'POST') { // … }