Sometimwes, we want to detect request type in PHP.
In this article, we’ll look at how to detect request type in PHP.
How to detect request type in PHP?
To detect request type in PHP, we can use the $_SERVER["REQUEST_METHOD"]
variable.
For instance, we write
if ($_SERVER["REQUEST_METHOD"] === "POST") {
// ...
}
to check if $_SERVER["REQUEST_METHOD"]
is 'POST'
.
If it is, then the script is invoked with a post request.
Conclusion
To detect request type in PHP, we can use the $_SERVER["REQUEST_METHOD"]
variable.