Get domain from api call using php?
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.
Your best bet is to check $_SERVER['HTTP_REFERER']
Just note that referrer can be spoofed, so if you are using it for authentication, don't. After you grab the $_SERVER['HTTP_REFERER']
you can then use this function to parse out the necessary stuffs: parse_url
精彩评论