If you do not know how a CSRF-attack work, read here
This is a simple class for taking care of generating and validating the tokens.
Let’s say that you have login.php in which a form with two text fields and a submission button are included. What you want to do here is to generate an access token and apply it to the login form as a hidden value.
To validate the token, apply the code below in the file where the login form has been posted to.