How to determine if a request is an ajax request?
1. We can judge by the X-Requested-With in the http protocol header information
2. If the ajax request is completed using jquery, there will be an HTTP-X-REQUESTED-WITH key value in $_SERVER. You can judge by this
For example:
if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ $username = isset($_POST['username']) ? addslashes($_POST['username']) : ''; $passwd = isset($_POST['passwd']) ? addslashes($_POST['passwd']) : ''; if($username == 'lh' && $passwd == 'passwd'){ echo 'hello baidu!'; } }else{ echo 'you must use ajax request!'; }
If it is an ajax request, what will be the referer corresponding to the request header information?
If it is an ajax request, the referer parameter corresponding to the request header information is the url of the current page
The above introduces how to determine whether a request is an ajax request? , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.