There are methods that will perform the Ajax request. The question is how to properly close access to such methods if they are not directly accessed via the Ajax? So far, of course, just checking what kind of request I am doing, but I would like to hear how to properly close access to such methods.

public function remove_holiday(){ if(!$this->input->is_ajax_request()){ echo 'Not ajax request'; }else{ $id = $this->input->post('id'); $result = $this->my_model->delete('holidays', array('id' => $id)); if($result){ echo json_encode(true); } } } 

    1 answer 1

    If by simple, then everything is correct, at the beginning of the method you check, you wrap all the logic with a check, for example, as in Yii. if (Yii :: app () -> request-> isAjaxRequest) {Your logic}. If you do not use the framework, you can check like this: / * AJAX check / if (! Empty ($ _ SERVER ['HTTP_X_REQUESTED_WITH']) && strtolower ($ _ SERVER ['HTTP_X_REQUESTED_WITH') == 'xmlhttprequest') {/ special ajax here * / die ($ content); }