Skip to content

Instantly share code, notes, and snippets.

@radenvodka
Created May 7, 2017 10:18
Show Gist options
  • Save radenvodka/03ace6a8bf5076dc9f1cad3bf84c1266 to your computer and use it in GitHub Desktop.
Save radenvodka/03ace6a8bf5076dc9f1cad3bf84c1266 to your computer and use it in GitHub Desktop.
Simple Anti CSRF
<?php
/**
* @Author: Eka Syahwan
* @Date: 2017-05-07 17:02:09
* @Last Modified by: Eka Syahwan
* @Last Modified time: 2017-05-07 17:16:45
*/
session_start();
class Security
{
public function csrfToken(){
$token = md5(date("dmY h:i:s").rand(10000,90000));
$_SESSION['token'] = $token;
return $_SESSION['token'];
}
public function csrfValidate($token){
if($token != $_SESSION['token']){
return false;
}else{
return true;
}
}
public function csrfHtml(){
echo '<input type="hidden" name="token" value="'.$this->csrfToken().'"></input>';
}
}
$security = new Security;
@radenvodka
Copy link
Author

how to use ?

call function csrfHtml()
for validate call function csrfValidate($_POST['token']);

@screetsec
Copy link

how to get married

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment