Hi friends.
Can you tell me how to know from which server/site I get curl request?
The story is something like that: I have API for some data. Users can get that data using query with API key. But in server (API) side I must detect is that valid key for user who send curl request to my API. How to do that? Did I need some more variables like secret key or something and how to do that?
API is in Laravel5 and use MySQL database.
Normally an API would be open, meaning you don't care where the request has come from.
What you would do is use token authentication to log a user in for that request. Within your API you would then check whether that user has permission to access the resource etc.
Here is an example of using JWT for API authentication
@bashy sorry to bother but what's the difference between curl and http_build_query? I'm trying to understand it and for what I saw on PHP.net it builds a query for GET requests, when you say "please use http_build_query()" you mean for GET requests?
@erozas That was directed at the code the previous person posted. They did a foreach() to loop through the query string items.
That is such a bad way to go about it. Using http_build_query() will put the & and = symbols in for you based on an array of data.
That's not an alternative to cURL, it's for use within cURL. You can do this as well to do a POST.
Thanks for the answer @bashy I make correction on my request. I find "josh-hornby/http" package to make request but I still have a problem: How to know from which server comes to my API request. I need to know that to make user use only one key for one site, not for many sites use one API key.
No. User have API key and it can use ti. In API server, I get his API key and see is that API key correct. But, I didn't want that user use that key for more than one application/website. I want limit user to use one API key to one website/application. Every application have one key. Can I do it and how to do it? For now I have generator API keys, API key to detect which user send request but didn't know is that requests from one website or from more than one website. I hope that is more clear :)
So, I must check IP of user who send request. Ok. But then I have another problem... how to enable user to use this in developing, on his localhost, and on the production server.