Onema
Onema

Reputation: 7582

PHP: how to get the host for an ajax request?

I have an API server, and I want to implement public an private api keys. The idea behind public API keys is to use them in javascript applications ajax calls from web browsers. In order to fully validate that the key I want to make sure the domain name it is coming from is in a list of trusted domains.

how would I get the host name for this kind of call?

Upvotes: 0

Views: 2736

Answers (1)

Marc B
Marc B

Reputation: 360672

Your API server would check $_SERVER['REMOTE_ADDR']. That'll get you the client's IP. If you're doing hostname-based filtering, you'd have to do a reverse DNS lookup to map that IP back to a hostname (e.g. gethostbyaddr()), though not all IPs have reverse mappings defined.

Upvotes: 1

Related Questions