Jump to content

Get To Know Websites That Connecting My Website's Api


Recommended Posts



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.





Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.