I try exprimentation with Codeigniter Security Class, because i want to implement any good feature on this framework to avoid my site from SQL Injection and Malicious Attack by hackers out there.
Question:
Why when i try to echo or print_r this get_csrf_hash()
, it just not appear anything.
My current codes
My Controller
<?php
class Myclass extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('session');
$this->load->helper('security');
$this->load->helper('form');
$this->my_simple_login->chek_login();
}
public function index(){
$this->load->view('/myform');
} // end index function (show form)
function submit_form(){
print_r( $this->input->post('my_input') ); // YEAH
print_r( $this->input->post('csrf_test_name') ); //empty??
print_r( $this->security->get_csrf_hash() ); //empty??
} //end form submitted
} // end class
My View
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<head></head><body>
<?php
$attributes = array('class' => 'my_html_class'); // add class to form HTML
echo form_open_multipart('myclass/submit_form', $attributes);
?>
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
<input name="my_input" value="YEAH"/>
<button type="submit" >SUBMIT FORM</button>
<?php echo form_close(); ?></body></html>
My CI Config
$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();