PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of mohammad anzawi   PHP CSRF Token Library   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP CSRF Token Library
Generate and validate tokens to avoid CSRF attacks
Author: By
Last change:
Date: 7 months ago
Size: 1,484 bytes
 

Contents

Class file image Download
<?php

include_once("Csrf.php");

$token = Csrf::init();


if (isset(
$_GET["ok"]) && isset($_POST)) {
/**


    if($token->checkToken($_POST['token']))
    {
        // process :)
    }
    else
    {
        // error :(
    }

    ////// OR ////////

    // without send token-value -> the class has been detected automatically
    if($token->checkToken())
    {
        // process :)
    }
    else
    {
        // error :(
    }

    ///// OR /////
    */

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

    // process last action
}


?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form action="?ok" method="POST">
   
        <input type="text">
        <br>
        <input type="submit" value="SUBMIT">
        <?php echo $token->csrfField() ?>

    </form>
    <br>
    <hr>
    <form action="?ok" method="POST">
   
        <input type="text">
        <br>
        <input type="submit" value="SUBMIT">
        <?php echo $token->csrfField() ?>

    </form>
    <br>
    <hr>
    <form action="?ok" method="POST">
   
        <input type="text">
        <br>
        <input type="submit" value="SUBMIT">
        <?php echo $token->csrfField() ?>

    </form>
    <br>
    <hr>
    <form action="?ok" method="POST">
   
        <input type="text">
        <input type="submit" value="SUBMIT">
        <?php echo $token->csrfField() ?>

    </form>
</body>
</html>