Я нахожусь в PHP script, и я хочу проверить, является ли запрос Ajax-запросом. (в основном, так как НЕ разрешить прямой доступ script, кроме вызова Ajax, который является...)
Итак, я определяю IS_AJAX
где-то в главном файле index.php
:
define('IS_AJAX',
isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
И затем, проверяя его в верхней части моего script:
if (!IS_AJAX) exit('No direct script access allowed');
Поскольку я новичок в CodeIgniter, я не уверен...
- Есть ли такие встроенные функции?
- Есть ли еще... элегантный способ сделать это?