Skip to content

Instantly share code, notes, and snippets.

@vladimir-light
Last active December 11, 2015 02:59
Show Gist options
  • Save vladimir-light/4534241 to your computer and use it in GitHub Desktop.
Save vladimir-light/4534241 to your computer and use it in GitHub Desktop.
Checks if request is a AJAX-Request
<?php
$ajax = false;
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
{
$ajax = true;
}
if (!$ajax)
{
header("HTTP/1.0 401 Not AJAX");
echo "<h1>HTTP Status : 401 - Access is denied!</h1>
<h3>Message: You have no permission to access this page</h3>";
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment