user3722573
user3722573

Reputation: 177

How to know, who made request?

How to know, who made POST request to my server?

Other server makes POST request to my servers API -> My server looks up who made this request. ( hostname )

Upvotes: 1

Views: 966

Answers (4)

user3722573
user3722573

Reputation: 177

Thanks everyone for answers.

Thanks to Nick I was able to get servers IP address. I went further and found this function -> gethostbyaddr()

This is what I initially wanted:

( taken from http://php.net/manual/en/function.gethostbyaddr.php )

$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

Hope this helps someone, as I didn't knew about this function before.

Upvotes: 0

vnay92
vnay92

Reputation: 318

If someone is hitting your API, you can always get details using $_SERVER['HTTP_REFERER']. You can also use $_SERVER['REMOTE_ADDR']. "-". $_SERVER['REMOTE_HOST'] to pin point and track with more efficiency.

Upvotes: 1

AMADANON Inc.
AMADANON Inc.

Reputation: 5929

There are multiple answers to this one.

As @Nick mentioned, there is the ip address that the request came from.

There is also the browser - this is also in the $_SERVER header.

If you want to know more, then you might need some sort of "password" to use your server - often called a "token", which uniquely identifies the requesting server - no token, no service. Then you will know.

Upvotes: 1

Bhavya Shaktawat
Bhavya Shaktawat

Reputation: 2512

You can use $_SERVER['REMOTE_ADDR'] for the server IP from which request is made.

Upvotes: 6

Related Questions