I have scripts from external domains that access our api script on our server, which returns information via json. My question is, if someone made the request from their site to our site for the api script can I get the url/domain the request came from? If so how would I do that? I tried using $_SERVER to get the domain name but that just gives me the domain the api script we host is on.
Im using PHP 4.x, yes will be upgrading soon but not now.
Accepted Answer
Your best bet is to check $_SERVER['HTTP_REFERER']
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki
Comments
gethostbyaddr()
Would this work for subdomains too? Or just the top level domain? So if someone accessed the api from subsite.mainsite.com will it just get mainsite.com? I guess it depends on the ip address.