I created a unique subdomain to provide data from my tables in JSON, it facilitates requests for both the mobile version and the desktop version of my site, but I would like to protect such data or at least make it difficult to access them , what could I do?
I thought of generating an access token to validate the request on the server, but this would invalidate the cache of the page (something I want to keep), not to use sessions because they are in different domains, it would be possible to at least block the direct access to the URL?
I'm also testing the method below, but I'm not sure it's safe
$origem = $_SERVER['HTTP_ORIGIN'];
if ($origem == "http://www.dominio.com" || $origem == "http://m.dominio.com")
{
header("Access-Control-Allow-Origin: $origem");
}
I do not believe that this way is safe because the data is still accessible through the direct api url, even though the individual may not be able to make requests, he can still open the page and copy the generated data.