2017-02-02 4 views
0

CI 웹 사이트에 csrf 보호 기능이 있습니다.csrf_protection이 true로 설정된 상태에서 Codeigniter가 오류를 표시합니다.

$config['csrf_protection'] = TRUE; 

따라서 새로 고침하여 양식을 다시 제출할 때 다음 오류가 발생합니다.

요청한 동작은 대신이 메시지를 보여주는의

을 허용되지 않습니다, 나는 그것이 마지막 페이지로 돌아가려면.

그래서, 나는 CI_Security 파일을 확장하여 csrf_show_error() 메소드를 오버라이드 (override)하려고합니다.

응용 프로그램/핵심에있는 내 클래스/My_Security.php

class MY_Security extends CI_Security { 

    public function __construct() 
    { 
     parent::__construct(); 
     $this->load->library('user_agent'); 
    } 

    public function csrf_show_error() 
    { 
     // show_error('The action you have requested is not allowed.'); // default code 

     // force page "refresh" - redirect back to itself 
     // a page refresh restores the CSRF cookie  
     if ($this->agent->is_referral()) 
     { 
      redirect(site_url()); 

     } else {    
      redirect($_SERVER['HTTP_REFERER']);   
     }   
    } 
} 

나는 비에()

전화 멤버 함수 라이브러리에 다음과 같은 오류를 얻고을 객체

답변

0

핵심 클래스를 변경하는 방법 응용 프로그램의 핵심 폴더에 MY_Securtiy 클래스가 생겼다. 과거 페이지로 리디렉션.

파일 위치 : 솔루션에 대한 응용 프로그램의 \ 코어 \ MY_Security.php

class MY_Security extends CI_Security { 

    public function __construct() 
    { 
     parent::__construct();  
    } 

    public function csrf_show_error() 
    { 
     header('Location: ' . htmlspecialchars($_SERVER['REQUEST_URI']), TRUE, 200); 
    } 
} 
0

감사하지만, 얻을 수있는 새로운 요청의 요청 유형을 변경하여 리턴 코드 (302)와 더 나은 것 같다 원래 요청 (예 : POST)에 사용 된 유형에 관계없이 다음 새로 고침은 어떤 질문도하지 않습니다.