I'm having a simple PHP page that generates random json values and returns it to the user. I want to know what website is using this page to get data using curl or javascript. for example:
the PHP page:
$datas['random'] = ['firstValue'=>'Hello', 'secondValue'=>'world'];
header('Content-Type: application/json');
echo json_encode($datas);
now that code will return this value
{"random":{"firstValue":"Hello","secondValue":"world"}}
what I want to do is: if someone used this file in his website using curl or javascript I want to be able to know which website is using it and what website requested it.
if the website http://example.com used this code in the website
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200) {
resolve(this.responseText);
} else if (this.response == null && this.status === 0) {
var reason = new Error('OFFLINE');
reject(reason);
} else {
var reason = new Error('ERROR');
reject(reason);
}
}
};
xhttp.open("GET", "jsonpage.php", true);
xhttp.send();
I want to be able to know that the website http://example.php requested the file, without using extra value jsonpage.php?website=example.com
is there any way to do it using PHP.