0

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

2
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by richprich
0

may I know how domains access your API? Is it through GET request or something else?

Example: yourSiteDotCom/api/search?q=something

0

Hi Veedeoo,

Yes, it's get request as your example. There is no API key needed.

Thanks.

1

There are PHP predefined variables called $_SERVER. This may help you.

I would look into the following variables

    HTTP_HOST
    HTTP_REFERER

There are plenty of resources online on how to implement this. I just don't have the time today to test it, but if ever you will not be able to find something, please let me know and I will write you the codes if needed.

The second option is making a minor changes on your API specifically on the GET request. So the remote site will have to add piece of codes to their requesting script.. for example, if your API accepts request like this

yourSiteDotCom/api/search?q=something

you can ask them to add something like this

$theirDomain = $_SERVER["HTTP_HOST"]; 

## the new query for sending an API request to your site

yourSiteDotCom/api/search?q=something&rsite=<?php echo $theirDomain;?>

On your API application, you can add simple codes like this

    if(isset($_GET['rsite'])){
    ## this is the domain name of the requesting remote site
    $remotSite = $_GET['rsite'];
    ## we need to clean this up and validate, and make sure it is a valid url
    if(filter_var($remoteSite, FILTER_VALIDATE_URL)){

    ## do what you need to do e.g. like adding it to your database

    }

    }
    ## allow other request from other site to get process.
    ## or you can use the PHP variables I have suggested above.

Edited by veedeoo: more info

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.