我是codeigniter的新手,如何在表单中验证CSRF令牌。
我的表单是:
<?php echo form_open('admin/create_cta', array('class' => 'navbar-form navbar-left', 'id' => 'new-cta')); ?>
<div class="form-group">
<input type="url" class="form-control" id="navbar-search-input" name="url" placeholder="Enter a URL">
<span class="form-group-btn">
<button type="submit" class="btn btn-info btn-flat">Create CTA</button>
</span>
</div>
<?php echo form_close(); ?>
的config.php
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Admin extends CI_Controller {
public function create_cta()
{
$data = $this->input->post();
var_dump($data);
}
}
我没有获得csrf输入值。这是&#34; var_dump($ data);&#34;结果
array (size=1)
'url' => string 'https://www.google.co.in/' (length=25)
答案 0 :(得分:0)
您可以获得Csrf令牌值,例如
Gradle 4.1-milestone
请参阅此链接https://www.codeigniter.com/user_guide/libraries/security.html