Last active
October 23, 2015 01:43
-
-
Save sword-jin/4412e17b5c3285fc7f6f to your computer and use it in GitHub Desktop.
CSRF token simple class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Token | |
{ | |
public static function generate() | |
{ | |
return $_SESSION['token'] = base64_encode(openssl_random_pseudo_bytes(32)); | |
} | |
public static function check($token) | |
{ | |
if (isset($_SESSION['token']) && $token === $_SESSION['token']) { | |
unset($token); | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment