Answer the question
In order to leave comments, you need to log in
Why doesn't PHP detect ajax request?
Good evening. On the Internet I found an example of defining an ajax request using php
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
// Если к нам идёт Ajax запрос, то ловим его
echo 'Это ajax запрос!';
exit;
}
//Если это не ajax запрос
echo 'Это не ajax запрос!';
var xhr = ajax._init();
xhr.open("GET", encodeURI(url), true);
>>>>>>>>>>>xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState==4 && xhr.status==200) {
callback.call(xhr.responseText);
}
Answer the question
In order to leave comments, you need to log in
On stackoverflow.com I read that this $servers variable is formed based on headers and they say that it cannot be trusted (I lost the link to the site with the question.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question