How to tell if a PHP script is being called by AJAX or from the browser?
The accepted answer to this question says
Modern browsers add the following request header when a request is made using the
XMLHttpRequest
object:X-Requested-With: XMLHttpRequest
In PHP, check the existence of this header using:
$_SERVER['HTTP_X_REQUESTED_WITH']
Bit that does not appear to work in PHP v 7.1.11, Chrome Version 63.0.3239.132 (Official Build) (64-bit)
Is there another way to distinguish?
[Update] I would prefer not to have to add an extra GET
or POST
parameter.