Reputation: 1673
I am working on codeigniter custom form, I need to work with CSRF token, so i have used $this->security->get_csrf_hash()
, but it is not working for me, can anyone please help mw how can i resolve this issue ? here is my code
<form role="form" data-parsley-validate="" novalidate="" class="mb-lg" action="?c=<?php echo isset($controller) ? $controller : "welcome"; ?>&m=login" method="post">
<div class="form-group has-feedback">
<input name="email" id="exampleInputEmail1" type="email" placeholder="Enter email" autocomplete="off" required class="form-control">
<span class="fa fa-envelope form-control-feedback text-muted"></span>
</div>
<div class="form-group has-feedback">
<input name="password" id="exampleInputPassword1" type="password" placeholder="Password" required class="form-control">
<span class="fa fa-lock form-control-feedback text-muted"></span>
</div>
<div class="clearfix">
<div class="pull-right"><a href="?c=<?php echo isset($controller) ? $controller : "welcome"; ?>&m=resetpassword" class="text-muted">Forgot your password?</a>
</div>
</div>
<?php
$csrf = array(
'name' => $this->security->get_csrf_token_name(),
'hash' => $this->security->get_csrf_hash()
);
echo "<pre>";
print_r($csrf);
die;
?>
<input type="hidden" name="<?php echo $csrf['name'];?>" value="<?php echo $csrf['hash'];?>" />
<button type="submit" class="btn btn-block btn-primary mt-lg">Login</button>
</form>
Upvotes: 0
Views: 1148
Reputation: 408
Please check in config file the following regeneration is true.
$config['csrf_regenerate'] = TRUE;
and in every post request pass the following name and value.
data:{get_csrf_token_name(): $this->security->get_csrf_hash()}
Upvotes: 1