Giter Site home page Giter Site logo

csrf-handler's Introduction

CSRF-Handler version stars commit

CSRF protection class file for Core-PHP.

CSRF - Cross Site Request forgery is a common and dangerous vulnerability in Web Sites/Applications. But we can fix it simply using tokens. This is simple PHP class file to help you to generate random tokens and verify it!

Usage

This class has just 3 functions called setToken(), checkToken(), flushKeys().

setToken()


setToken() function is used to generate random token.

Example

<?php 
  include("csrfhandler.lib.php");
?>

<form action="" method="post">
    <input type="hidden" name="_token" value="<?php echo csrf::setToken();?>"/>
</form>

checkToken()


checkToken() function is used to check the incoming random token.
If the token valid, It will return true, Otherwise It will return false

Example

<?php

include("csrfhandler.lib.php");

$token = $_POST["_token"];
$isValid = csrf::checkToken($token);

if($isValid == true){

//your code if valid

}else{

//your code if not-valid

}

?>

flushKeys()


flushKeys() function is used to delete all active CSRF Token Keys from Session.


Example

<?php

include("csrfhandler.lib.php");

  csrf::flushKeys();

?>

csrf-handler's People

Contributors

banujan6 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.