本文翻譯自: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? 任何的想法?
#1樓
參考:https://stackoom.com/question/5kxP/檢查請求是GET還是POST-重複
#2樓
使用$_SERVER['REQUEST_METHOD']
。
#3樓
Better use $_SERVER['REQUEST_METHOD']
: 最好使用$_SERVER['REQUEST_METHOD']
:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// …
}