Skip to content

Instantly share code, notes, and snippets.

@admataz
Created June 7, 2011 11:41
Show Gist options
  • Save admataz/1012073 to your computer and use it in GitHub Desktop.
Save admataz/1012073 to your computer and use it in GitHub Desktop.
Function to detect whether the current request is from XMLHTTPREQUEST
<?
/*
* Detect whether the current query is ajax
*
* TODO: check if this works across browsers and ajax libraries
*/
function is_xhr()
{
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
return true;
}
else
{
return false;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment