PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of mohammad anzawi   PHP CSRF Token Library   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Read me
Class: PHP CSRF Token Library
Generate and validate tokens to avoid CSRF attacks
Author: By
Last change:
Date: 1 year ago
Size: 1,327 bytes
 

Contents

Class file image Download

phptricks :)

CSRF-class :

its easy to use , its simple already

How to Use :

1 - include CSRF-class to your project :

<?php 

include_once("project-dir/libs/Csrf.php");

2 - initialize CSRF-class :


$token = CSRF::init();

3 - check if token its match :


// first method
if($token->checkToken())
{
    // process last action
}
else
{
    // Oops, something error (SCRF Attack)
}

// you can send token value to this method
if($token->checkToken($_POST['token']))
{
    // process last action
}
else
{
    // Oops, something error (SCRF Attack)
}


// other method :

$token->validOrDie(); // any error ??? then kill the page

// process last action

helpers ?

we have only one public helper , its :

csrfField()

this method to create token input field.


<form action="?ok" method="POST">

    <input type="text">
    <br>
    <input type="submit" value="SUBMIT">
    <?php echo $token->csrfField() ?>

</form>

in other hand you can create this field manually and pass token value


<form action="?ok" method="POST">

    <input type="text">
    <br>
    <input type="submit" value="SUBMIT">
    
    <input type="hidden" name="_token" value="<?php echo $token->getToken() ?>">
</form>

I Hope that Help You :)))

License : MIT