Skip to content

Instantly share code, notes, and snippets.

@maximevalette
Created April 6, 2011 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximevalette/905746 to your computer and use it in GitHub Desktop.
Save maximevalette/905746 to your computer and use it in GitHub Desktop.
Allow scripts to "die" following the HTTP Request type (AJAX or not)
<?php
/**
* Allow scripts to "die" following the HTTP Request type (AJAX or not)
* @param $msg Message to send if sent through AJAX
* @return void
*/
function xhrDie($msg) {
$headers = apache_request_headers();
if ($headers['X-Requested-With'] == 'XMLHttpRequest') {
die($msg);
} else {
header('Location: '.$_SERVER['HTTP_REFERER']);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment