if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Process form data }
switch ($_SERVER['REQUEST_METHOD']) { case 'GET': // Process GET request break; case 'POST': // Process POST request break; case 'PUT': // Process PUT request break; default: // Handle unsupported method break; }This code example uses the getMethod to detect the HTTP request method used and then switches to process the appropriate request method. The getMethod is a built-in method in PHP and doesn't require any additional package or library.