I have recently started to code heavily AJAX supported scripts in PHP, thing is, the files being accessed by the AJAX calls can be directly used too, how to disable that?
There's no way of directly disallowing access. Since a query can always be crafted to match any criteria you come up with.
If XmlHttpRequest is being used to query the server it adds a header which can be detected using something like:
/* AJAX check */
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
//Do something here
}