0

Good day, I have created a PHP API, that accepts GET/POST requests.

I would like to get the IP address of the server which made a request to my API in order for me to do some verification.

I tried to use $_SERVER['REMOTE_ADDR'] value for that, but noticed that it doesn't work well with all kind of websites.

I tried to search online for a solution, but only found how to get client's IP.
And I guess that "client" means the user that triggered the API call.

What I need is the website's server address from which request has been made.
Could someone offer a better way to do that?

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
motleycrue
  • 81
  • 1
  • 9

1 Answers1

-1

APIs can be called from a server - e.g., another PHP script - or from client side - typically Javascript in a browser using AJAX, which is much more common. For example, a Javscript snippet for Google Analytics, Google Maps, etc. will be included in plenty of web pages but the actual call to Google will be done by the client browser. In those situations, which I think is typical for many (most?) APIs, the only IP address you will see is the client, not the web server. The solution Google (and many other APIs) use is to require registration for a free API key in order to use the API. You can't usually track that to a specific web server, but it does allow you to connect with the initial customer or developer who registered for the API.

TL;DR Create a free "API Key" for your web site users/customers/developers and track them that way.