PHP Tips & Tricks

How to Check Ajax Request with PHP

How to Check Ajax Request with PHP July 27, 2017Leave a comment

Hello World, I am Chandra Kumar from New Delhi, India. I am professionally developer, programmer and blogger. I am the founder of WebShouters.com.

In this tutorial, you will go through how to check ajax request with php scripts. This trick will be very useful and handy when you want the same request to behave differently for AJAX request and normal.

In PHP, The $_SERVER['HTTP_X_REQUESTED_WITH'] variable is one strong sign that an AJAX request has been made from browser. header is sent by all recent browsers that support AJAX requests.

$is_ajax = false;

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) 
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') 
{
  $is_ajax = true;
}

Hope this is useful for you 🙂

How to Check Ajax Request with PHP
Rate this post

(Visited 2 times, 1 visits today)

Hello World, I am Chandra Kumar from New Delhi, India. I am professionally developer, programmer and blogger. I am the founder of WebShouters.com.

Leave a Reply

Your email address will not be published. Required fields are marked *