Last updated on July 7, 2017
The HTTP_X_REQUESTED_WITH header is sent by all recent browsers that support AJAX requests.
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) { // something }