[PHP] Allow access to PHP file for AJAX call only from files on local server
It is worthwhile to check with phpinfo() function if sever variables are all available for your server to implement the code as below.
$pos = strpos($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']);
if($pos===false)
die('Restricted access');