Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSRF protection #3

Open
andreakru opened this issue Oct 19, 2014 · 0 comments
Open

CSRF protection #3

andreakru opened this issue Oct 19, 2014 · 0 comments

Comments

@andreakru
Copy link

hi

I have added a csrf protection to the class, you can see here:

https://github.com/macagoraga/form/commit/d0cad864f75de097fef2b47378d3bc5adeaaec4f

Usage:

<?php
$form = new Form();

// enable csrf passing key used for $_SESSION and $_POST
$form->enableCsrf('csrf_token');

// add csrf token into hidden field
$form->csrfToken();

$form->text('username');
$form->password('password');
$form->password('confirm_password');

$form->submit('submit_button', 'Click to Continue');

// when post is submit, check token
if($form->checkCsrf()) echo 'csrf passed';
else echo 'csrf failed';

// optional we can add timestamp, so token expire after X minutes
$timespan = 10; // 10 minutes
$onetime = false; // disable use token onetime, usefull when ajax 
$throwException = true; // trow an exception if failed
if($form->checkCsrf($timespan, $onetime, $throwException))
...

Inspired by https://github.com/BKcore/NoCSRF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant