Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a script that's supposed to detect the url of its caller website. If the caller is another website, it should give something like http://callersite.com. I'm using this line of php code (though I suspect this won't matter for sysadmins)

gethostbyaddr($_SERVER['REMOTE_ADDR'])

I'm testing with a caller site that's hosted on hostgator. What I'm noticing though is that I don't get callersite.com, I get something like 1a.12.12ab.static.theplanet.com. I don't know what theplanet.com is and why I'm not getting caller site.com.

Also what do I need to do to really get the domain of the site making a call to my script?

--

Thanks for the explanation. Some have advised I use $_SERVER['HTTP_REFERER'] but it's not what I'm after. My script acts as an API. Another website makes a curl request to it and gets an output and later on presents it to the user. So http referrer gives false since the caller site.com is making a direct call to me. So any hope?

share|improve this question

4 Answers 4

Hostgator servers are hosted in Theplanet DC, now Softlayer, thats why you get 1a.12.12ab.static.theplanet.com as host name. The user doesn't have RDNS(or on shared) which is what

gethostbyaddr($_SERVER['REMOTE_ADDR'])

gets so its getting theplanets default. You could look at this which will pull the address the user came from.

$ref=@$HTTP_REFERER;

share|improve this answer
    
Good one Jacob! ;) +1 –  lynxman Feb 10 '11 at 11:59
    
@lynxman thanks –  Jacob Feb 10 '11 at 12:02
    
+1 but unfortunately $_SERVER['HTTP_REFERER'] isn't what I'm after. Let me explain: my script acts as an API. Another website makes a curl request to it and gets an output and later on presents it to the user. So http referrer gives false since the caller site.com is making a direct call to me. So any hope –  silow Feb 10 '11 at 12:08
    
So you want the domain correct? If your only getting an IP than you may be out of luck –  Jacob Feb 10 '11 at 12:13
    
You could have a signup for your api generate that a hash and deny anyone without a hash to identify. –  Jacob Feb 11 '11 at 11:40

"gethostbyaddr" gets the reverse dns for a connection ip address. What you are probably looking for is the referrer, which is available in echo $_SERVER['HTTP_REFERER'];

share|improve this answer
    
+1 but unfortunately $_SERVER['HTTP_REFERER'] isn't what I'm after. Let me explain: my script acts as an API. Another website makes a curl request to it and gets an output and later on presents it to the user. So http referrer gives false since the caller site.com is making a direct call to me. So any hope –  silow Feb 10 '11 at 12:08

gethostbyaddr does a reverse lookup of the IP address. If this IP address belongs to an ISP provider, in this case theplanet.com or softlayer.com, then you will get a pointer to a generic name they defined.

callersite.com is just an alias for that IP, but not the real name or pointer.

If you are on linux, try

dig callersite.com

or on Windows

nslookup callersite.com

Or go to a page like http://www.dnsqueries.com/en/ and start your DNS queries there.

share|improve this answer
1  
He doesn't have the domain but needs to find it from the IP –  Jacob Feb 10 '11 at 12:21

It's easy to add extra headers to the request with curl. If the other side can modify their script they could just append the information you need. Since you're building an API just make the extra header part of the specification.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.