Created
April 6, 2011 14:33
-
-
Save maximevalette/905746 to your computer and use it in GitHub Desktop.
Allow scripts to "die" following the HTTP Request type (AJAX or not)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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