Check whether a request is GET or POST

Possible Duplicate:
PHP detecting request type (GET, POST, PUT or 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.

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?


更好地使用$_SERVER['REQUEST_METHOD']

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // …
}

使用$_SERVER['REQUEST_METHOD']

链接地址: http://www.djcxy.com/p/58524.html

上一篇: 如何在PHP中获取客户端IP地址?

下一篇: 检查请求是GET还是POST