Hi, i am giving this function regarding detection of ajax call in php. The PHP Super Global Variable
$_SERVER['HTTP_X_REQUESTED_WITH'] it checks how the client machine request the server..
The below is the function is_ajax_request() it will check the request type and return true or false.
<?php
function is_ajax_request()
{
return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
}?>
Example :
<?php if(!is_ajax_request()){
require_once('includes/header.php')
}?>
$_SERVER['HTTP_X_REQUESTED_WITH'] it checks how the client machine request the server..
The below is the function is_ajax_request() it will check the request type and return true or false.
<?php
function is_ajax_request()
{
return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
}?>
Example :
<?php if(!is_ajax_request()){
require_once('includes/header.php')
}?>
0 comments:
Post a Comment