The PHP function isXhr is used to detect whether a request was made by XMLHttpRequest in the browser. This function returns a boolean value of true if XMLHttpRequest was used, otherwise it returns false.
Example 1:
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { // This request was made by XMLHttpRequest // Perform some action here } ?>
In this example, the server checks whether the HTTP header 'HTTP_X_REQUESTED_WITH' is set and its value is 'xmlhttprequest', indicating that the request was made by XMLHttpRequest. If this condition is met, some action can be performed in the server.
Example 2:
// The following function returns true if the request was made by Ajax/XmlHttpRequest function isXhr() { return !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; } ?>
In this example, the function isXhr is defined to simplify the checking of whether the request was made by XMLHttpRequest. The function returns a boolean value that can be used in conditional logic in the server.
The package library for this functionality is likely the php-http package, which provides a PHP HTTP client and server interfaces, as well as utilities to make working with HTTP easier.
PHP Request::isXhr - 30 examples found. These are the top rated real world PHP examples of Request::isXhr from package someline-starter extracted from open source projects. You can rate examples to help us improve the quality of examples.