SuperMonkey

token csrf

Jul 8th, 2013
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.40 KB | None | 0 0
  1. <?php
  2.  
  3. // à appeler à chaque page
  4. function token_gen() {
  5.     $_SESSION["token"] = (!empty($_SESSION["token"])) ? $_SESSION["token"] : substr(md5(mt_rand(0,10000) . "haha" .time()), 6);
  6. }
  7.  
  8. // à appeller à chaque vérification de token
  9. function token_check($arr) { //$arr peut être $_POST ou $_GET
  10.     if ($_SESSION["token"] != $arr["csrf_token"])
  11.         throw new Exception("CSRF token invalide");
  12. }
  13.  
  14. ?>
Advertisement
Add Comment
Please, Sign In to add comment