ADVERTISEMENT


Breaking News

Recent Posts

Sunday, September 13, 2015

How to detect Ajax Request in PHP

In php you can detect that request send on your page is from ajax or not, 
Ajax requests usually set X-Requested-With request header which is set by different kind of js libraries i.e jQuery , Mootools



So its very good technique to use below script on top of your page if you want only ajax request acceptable. In other case you can show him Warning message.

 if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {  
   echo 'Only Ajax requests acceptable';  
 }  

No comments:

Post a Comment

Designed By Published.. Blogger Templates