I am using GroceryCRUD 1.5.0 with CodeIgniter 2.2.0.
When enabling CodeIgniter's internal CSRF protection with:
$config['csrf_protection'] = TRUE;
in application/config/config.php
, then the GroceryCRUD auto-generated action buttons (edit, view) and links (add) does not work anymore.
It seems that the CSRF token is not passed along in the Ajax calls (confirmed with Firebug). It is possible to use this CodeIgniter feature with GroceryCRUD?
I finally managed to solve my problem. Two options are available:
The easy way:
Set:
$config['grocery_crud_dialog_forms'] = false;
in application/config/grocery_crud.php
.
이 옵션은 CSRF 보호를 사용하지 않아도 잘 작동하지만 (즉, true
보다 우아한 양식을 생성 하도록 설정할 수 있음 ) 자바 스크립트에서 코드 수정이 수행되지 않으면 설정하면 실패합니다.
우아한 방법 :
사용하려는 경우 :
$config['grocery_crud_dialog_forms'] = true;
의는 application/config/grocery_crud.php
다음, 귀여운 모양을 가지고 :
양식이있는 페이지에 jquery.cookie 플러그인 포함
이 코드를 JS 파일에 추가하여 모든 ajax POST 호출에 CSRF 토큰을 자동으로 삽입합니다.
$(document).ready(function() {
var csrf_token= $.cookie('csrf_cookie_name');
$.ajaxSetup({
data: {
'csrf_test_name' : csrf_token
}
});
});
다른 사람에게 도움이되기를 바랍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다