For the normal ajax request I use:
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'
But this don’t work with cross domain request.
How can I do?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Edit2:
If you’re using jQuery.ajax function in this way:
Then you can check the
$_SERVER['REQUEST_URI']variable, or simply$_GET['callback']and$_GET['_']. The REQUEST_URI will look like this:/somescript.php?somevar=somevalue&callback=jQuery172028849187534502896_1333494007273&_=1333494443880
Edit: The answer below is to find out if it is cross-domain or not, not checking if it is AJAX
The answer to the question “How to determine if an ajax-call is from a different domain” is this:
I’m using the jQuery.ajax call, and for me using the variable
$_SERVER['HTTP_REFERER']works fine.If I’m using a page on my local computer, this superglobal returns an empty string.
If I’m using a page on the internet, the value of
$_SERVER['HTTP_REFERER']returns the URL of the page that made the ajax call. So checking the value of this can tell you what you need to know.