richprich Posted December 30, 2012 Share Posted December 30, 2012 Hi, I have an API script provided to people fetching data from my website. Other than stats information, how can I get to know that which websites are connecting my website's API? Any php function that I can include in my API script to get their domain names then insert into my database? I am php newbie. It would be appreciated if you can post your complete function codes here. Thanks, Richard Quote Link to comment https://forums.phpfreaks.com/topic/272514-get-to-know-websites-that-connecting-my-websites-api/ Share on other sites More sharing options...
gizmola Posted December 30, 2012 Share Posted December 30, 2012 What is built-in is the $_SERVER['REMOTE_ADDR'] which will give you the IP address of the visitor. Store this, and you can use [m]gethostbyaddr[m] which will do a reverese dns lookup based on the IP and return you a hostname. Lookups like these can be very slow, especially when there isn't proper DNS, so you probably don't want to have your api scripts doing this lookup and storage during the api calls. You're better off writing a seperate script that goes through your database of visitor IP's, does the gethostbyaddr calls and updates a hostname field in the db. Keep in mind that there is no guarantee that an IP has a hostname associated with it, nor is there a guarantee that the hostname you get from the reverse is going to tell you what you want to know. For example, a shared hosting server could have hundreds of companies sharing the same IP address, and the reverse DNS if it has been set, will only point you to the hosting company. Quote Link to comment https://forums.phpfreaks.com/topic/272514-get-to-know-websites-that-connecting-my-websites-api/#findComment-1402157 Share on other sites More sharing options...
richprich Posted December 30, 2012 Author Share Posted December 30, 2012 Yes, this is the problem of $_SERVER['REMOTE_ADDR'] IP look up. I can't get the domain name if they are using a share IP. Any solution? Quote Link to comment https://forums.phpfreaks.com/topic/272514-get-to-know-websites-that-connecting-my-websites-api/#findComment-1402229 Share on other sites More sharing options...
Christian F. Posted December 30, 2012 Share Posted December 30, 2012 Only solution would be to have them send some piece of identifying information. Either in the form of the actual domain (which can be spoofed easily), or by some unique identifier (which they have to keep secret). In either case, you have to rely upon the client to send you that information. Quote Link to comment https://forums.phpfreaks.com/topic/272514-get-to-know-websites-that-connecting-my-websites-api/#findComment-1402231 Share on other sites More sharing options...
cpd Posted December 30, 2012 Share Posted December 30, 2012 As Christian touched on you'd need people to register and use a unique identifier. Its one reason why the likes of Facebook, Twitter and many more require developers to register before interacting with their APIs - far stricter and they can keep tabs on things. Quote Link to comment https://forums.phpfreaks.com/topic/272514-get-to-know-websites-that-connecting-my-websites-api/#findComment-1402250 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.