E
E
efilatus2022-01-30 19:25:24
PHP
efilatus, 2022-01-30 19:25:24

How to properly process requests in PHP?

Only now an interesting task has appeared, to make a file that will receive json data from another server, and process it. With the processing of these questions, questions cannot arise, but the processing of the request itself has baffled me. I need to check that the request contains json and a certain header, so that no one could just throw requests, but that’s bad luck, I can’t find examples to understand how it all works.
I used curl to send requests and accept responses to these requests, but I don’t understand how to make a handler that could check the data that comes and give the correct answer.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rPman, 2022-01-30
@efilatus

I need to check that the request contains json and a certain header, so that no one could just throw requests
historically this is done through authorization
Add basic auth either on the web server side or directly in php a matter of a few lines . To send a request to almost any library, you can use the following url format - http://user:[email protected]/path (even php file_get_contents supports)
Well, the simplest thing - by token,
the token is literally a password, which is either registered in the configs / sources your service or issued by the authorization service for a while. This token can be specified either in the headers (then to send a request, you need to set this header, or even easier - place this token directly in the request, i.e. site.com/doit?auth=secret_password
If the protocol for communicating with your server is https, no one will be able to find out either the login password or the authorization token without having access to the machine from which they are called

F
FanatPHP, 2022-01-30
@FanatPHP

I can't find examples to understand how it all works.

Is that really serious ?
There is no information on the internet on how to process a JSON POST request in PHP?
Not a single example? Roskomnadzor banned Google, Yandex, Bing and Rambler?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question