jquery Ajax is used here.
Page:
$.ajax ({
Type: ' POST ',
URL: ' http://www.yourwebsite.com ',
Beforesend:function (XMLHttpRequest) {
Xmlhttprequest.setrequestheader ("Request_type", "Ajax");
},
Data: ' Test=test ',
Success:function (RS) {
Alert (' OK ');
}
}
});
PHP Code:
echo isset ($_server[' Http_request_type ')) && $_server[' http_request_type '] = = "Ajax"? "It is Ajax": "It's not Ajax.";
There is another way, JS inside without adding beforesend inside the code, directly in PHP to make judgments:
echo isset ($_server[' http_x_requested_with ') && $_server[' http_x_requested_with ']=== ' XMLHttpRequest '? ' It is Ajax ': ' It's not Ajax ';
PS: Determine if the data is flash submission
echo isset ($_server[' http_user_agent ')) && (Stripos ($_server[' http_user_agent '], ' Shockwave ')!== false | | Stripos ($_server[' http_user_agent '), ' Flash ')!== false)? Echo ' It is flash data ': ' It's not flash data ';