How to get and process JSON data from a POST request in PHP?
Hello everyone! I'm a beginner in PHP and trying to understand REST API. I need to write a script that accepts JSON data via a POST request and saves it to a database.
The problem is that I cannot get this data using the standard method. When I send a regular form with Content-Type: application/x-www-form-urlencoded, everything works through $_POST. But as soon as I switch to JSON (Content-Type: application/json), the $_POST array turns out to be empty.
Here is my current code:
```php
```
I'm sending a request via Postman with the following body:
```json
{
"name": "Ivan",
"email": "ivan@example.com",
"age": 28
}
```
But an empty array is written to the log.txt file. I read that