PHP中,我们可以通过$_SERVER['REQUEST_METHOD']
来判断当前的请求类型。下面是一个判断当前请求类型的示例代码:
<?php
function getRequestMethod()
{
$request_method = $_SERVER['REQUEST_METHOD'];
switch ($request_method) {
case 'GET':
return 'get';
case 'POST':
return 'post';
case 'PUT':
return 'put';
case 'PATCH':
return 'patch';
case 'DELETE':
return 'delete';
case 'AJAX':
return 'ajax';
default:
return 'unknown';
}
}
echo getRequestMethod()."请求";