When working with external services, like API, we need to debug request type from external URL. Sometimes debugging in Javascript also need to find request type.
In PHP, there is $_SERVER
global variable that returns server details with request details. You can catch request type with $_SERVER['REQUEST_METHOD']
variable. Here is example code of how to find request type.
<?php
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST') {
// POST method
} elseif ($method == 'GET') {
// GET method
} elseif ($method == 'PUT') {
// PUT method
} elseif ($method == 'DELETE') {
// DELETE method
} elseif ($method == 'PATCH') {
// PATCH method
} elseif ($method == 'OPTIONS') {
// OPTIONS method
} elseif ($method == 'COPY') {
// COPY method
} elseif ($method == 'UNLINK') {
// UNLINK method
} elseif ($method == 'LINK') {
// LINK method
} elseif ($method == 'PURGE') {
// PURGE method
} elseif ($method == 'LOCK') {
// LOCK method
} elseif ($method == 'UNLOCK') {
// UNLOCK method
} elseif ($method == 'VIEW') {
// VIEW method
} else {
// unknown method
}
There is also another method to find request type. It returns same response as above. You can use filter_input()
method to find out request type.
$request = filter_input(INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_ENCODED);
I hope it will help you.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Django - How to send an email with Example
Django comes with a yare and facile-to-u...How to set Limit on Login Attempt in Laravel7
Hey Artisan Did you ken that you can...How to check if record exists or not in Laravel
In this article, I will show you how you...Laravel 7 - Multiple Image Upload with Preview using AJAX
In this article, i will let you know aja...How to Send Email with Attachment in Laravel 8
Sending mail with attachment is always c...