How to detect Ajax Request in PHP
Today, we will know how to detect ajax request in PHP. if you want to know if that is an ajax request or not. so you can below example you can easily know if that ajax request or not.
we will use the HTTP_X_REQUESTED_WITH to check if the incoming request is AJAX.
1 2 3 4 5 6 7 | <?php if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { echo "This is Ajax Request"; exit; } ?> |
Please follow and like us: