GroceryCRUD add, edit buttons not working when enabling CodeIgniter CSRF protection

jrierab

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?

jrierab

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다음, 귀여운 모양을 가지고 :

  1. 양식이있는 페이지에 jquery.cookie 플러그인 포함

  2. 이 코드를 JS 파일에 추가하여 모든 ajax POST 호출에 CSRF 토큰을 자동으로 삽입합니다.

$(document).ready(function() {
    var csrf_token= $.cookie('csrf_cookie_name');

    $.ajaxSetup({
        data: {
            'csrf_test_name' : csrf_token
        }
    });	
});

다른 사람에게 도움이되기를 바랍니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Codeigniter not working properly when hosted

분류에서Dev

codeigniter CSRF 오류

분류에서Dev

enabling HTTPs on weblogic server not working

분류에서Dev

CodeIgniter CSRF 403 오류

분류에서Dev

Bootstrap: Buttons not working

분류에서Dev

Working with Radio Buttons

분류에서Dev

how to manually add csrf token

분류에서Dev

.htaccess hotlink protection - add image exception

분류에서Dev

Form action not working in codeigniter

분류에서Dev

Codeigniter: Redirect not working

분류에서Dev

Codeigniter - Pagination not working correctly

분류에서Dev

Codeigniter / Migration Not Working

분류에서Dev

Google spreadsheet - Error when Remove range protection

분류에서Dev

Microsoft Management Console stops working when I add snap-in to it

분류에서Dev

hover stops working when I add more element

분류에서Dev

AngularJS edit record behaviour not working

분류에서Dev

csrf_protection = true로 기능 테스트 실패

분류에서Dev

Add buttons for custom styles to CKEditor

분류에서Dev

csrf로 codeigniter dropzone ajax 업로드

분류에서Dev

CSRF Codeigniter 보호 및 AJAX 호출

분류에서Dev

Codeigniter get_csrf_hash () 빈 반환

분류에서Dev

CodeIgniter 3의 CSRF 및 Ajax 문제

분류에서Dev

CodeIgniter Flexi Auth Demo is Not working

분류에서Dev

AutoHotkey - application loosing focus when enabling full screen mode

분류에서Dev

Disabling touchEnd when pressing buttons

분류에서Dev

ADD and Multiply array data in codeigniter

분류에서Dev

AngularJS ui grid edit not working with group

분류에서Dev

Required Field validator in edit item template is not working

분류에서Dev

Codeigniter - Only allow specific user to edit/delete post