Welcome Guest, Not a member yet? Register   Sign In
CI4 csrf_field not generate same value as csrf_hash
#1

I'm trying to implement csrf validation in my form.
based on my understanding, we just compare the csrf hash from view/post with the csrf in backend/controller.
so, i tried to use 

Code:
<?= csrf_field() ?>
 in my view page, then do some comparison
Code:
if ($this->request->getPost(csrf_token()) === csrf_hash()) {
#do some stuff
}
result: the hash value is different.
but it wont be an issue if i use 

Code:
csrf_token() and csrf_hash()
 in the form. the hash generated always same.
how to solve this or do the validation bt using the csrf_field? as per documentation, it only stated the way we can retrieve the value with the same exact thing that I've done.
fyi, I'm not using 

Code:
form_open()
 as i would prefer to do the html by myself with some bootstrap.
Reply


Messages In This Thread
CI4 csrf_field not generate same value as csrf_hash - by nmaa3003 - 06-02-2020, 06:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB