Created
March 4, 2012 00:46
-
-
Save piercemoore/1969492 to your computer and use it in GitHub Desktop.
Super Simple AJAX Detection in PHP
This file contains hidden or 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 | |
| /* | |
| * isAjax determines whether a server request is a standard browser-based request or if it is being loaded via AJAX. | |
| * | |
| * REMEMBER: Do NOT use this for security purposes as it is VERY easy to spoof headers. | |
| * | |
| * @return bool | |
| */ | |
| function isAjax() { | |
| $param = $_SERVER['HTTP_X_REQUESTED_WITH']; | |
| if( ( isset( $param ) && !empty( $param ) ) && ( ( strcmp( $param , 'XMLHttpRequest') ) == 0 || ( strcmp( $param , 'xmlhttprequest' ) == 0 ) ) ) { | |
| // Yep. It's AJAX. | |
| return true; | |
| } | |
| return false; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment