Да, можно, и у вас есть два варианта:
1- простой способ, просто изменив «/ приложения config.php» файл, как это:
$config['csrf_protection'] = FALSE;
if (isset($_SERVER["REQUEST_URI"]))
if(stripos($_SERVER["REQUEST_URI"],'/login') !== FALSE
|| stripos($_SERVER["REQUEST_URI"],'/register') !== FALSE
)
$config['csrf_protection'] = TRUE;
2- Переопределяя безопасности Класс и создание крюка класса следующим образом:
2-1 Приложение/ядро / My_Security.php:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Security extends CI_Security
{
public function regenerate_csrf_hash()
{
// CSRF config
foreach (array('csrf_expire', 'csrf_token_name', 'csrf_cookie_name') as $key) {
if (false !== ($val = config_item($key))) {
$this->{'_' . $key} = $val;
}
}
// Append application specific cookie prefix
if (config_item('cookie_prefix')) {
$this->_csrf_cookie_name = config_item('cookie_prefix') . $this->_csrf_cookie_name;
}
// Set the CSRF hash
$this->_csrf_set_hash();
$this->csrf_set_cookie();
}
}
2-2 приложения/крючки/EnableOptions.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class EnableOptions {
private $ci;
public function __construct(){
$this->ci = &get_instance();
}
public function enableCSRF()
{
if ($this->ci->config->item('csrf_protection') === false) {
$uri = $this->ci->config->item('enable_csrf_for_uris_only');
$segment = $this->ci->uri->segment('1'); // 1 : for controller name
if (in_array($segment, $uri)) {
$this->ci->config->set_item('csrf_protection', true);
$this->ci->security->regenerate_csrf_hash();
}
}
}
}
2-3 приложения/Config/hooks.php:
$hook['post_controller_constructor'][] = array(
'class' => 'EnableOptions',
'function' => 'enableCSRF',
'filename' => 'EnableOptions.php',
'filepath' => 'hooks',
'params' => array()
);
2-4 приложения/Config/config.php: Включите крючки путем изменения "enable_hooks" истина,
$config['enable_hooks'] = TRUE;
и добавить дополнительный параметр для URIs,
$config['enable_csrf_for_uris_only'] = array('login', 'register');
Всё.