Avatar ·

How to determine HTTP request type (GET, POST, PUT, DELETE) in PHP?

Hello everyone! I'm a beginner in PHP and writing a simple REST API for a study project. I need the script to handle different request types: GET for retrieving data, POST for creating, PUT for updating, and DELETE for deleting. The problem is that I can't figure out how to correctly determine which HTTP method is used in the current request. I've seen many different examples online, but they all contradict each other. Some use `$_SERVER['REQUEST_METHOD']`, some suggest checking `$_POST` or `$_GET`, and others talk about hidden fields in forms. Here's my current code that doesn't work as expected: ```php ```