M
M
MrLincomins2022-02-24 20:25:23
PHP
MrLincomins, 2022-02-24 20:25:23

How to catch and read http request?

Hello, I have a scanner that sends me an http request with the content of application/json. It contains the following data:
{"Name": , "Login": <string>, "Password": <string>, "Year of birth": }
How can I catch this query and read the data (raise each to their separate variable) ?
Thanks in advance! I use php 7.4.9

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Megas, 2022-02-24
@MrLincomins

//Считываем данны из тела HTTP запора
$json = file_get_contents('php://input');
//Превращаем JSON строчку в PHP массив
$data = json_decode($json);

//Содержимое переменной $data
// [
//         "Имя" => <строка>, 
//         "Пароль" => <строка>, 
//         "Год рождения" => <строка>, 
// ]

F
FanatPHP, 2022-02-24
@FanatPHP

Greetings.
Every site on the world wide web does the same.
Everyone.
This is one of the most common tasks in web development.
There are millions of examples online on how to do this.
Try once in a lifetime to use the search.

N
Nikolai Savelyev, 2022-02-24
@AgentSmith

Put logs in the place where requests are received

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question