Advertisement
thecodepress

Cross site request forgery (CSRF) Protection in PHP

Mar 18th, 2014
4,194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. Class Security
  2. {
  3.     public static function getToken()
  4.     {
  5.         $token = sha1(uniqid());
  6.         $_SESSION['token'] = $token;
  7.         return $_SESSION['token'];
  8.     }
  9.  
  10.     public static function checkToken($token)
  11.     {
  12.         if (isset($_SESSION['token'])) {
  13.             if ($token == $_SESSION['token']) {
  14.                 unset($_SESSION['token']);
  15.                 return true;
  16.             }
  17.         }
  18.  
  19.         return false;
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement