Skip to content

Instantly share code, notes, and snippets.

@sword-jin
Last active October 23, 2015 01:43
Show Gist options
  • Save sword-jin/4412e17b5c3285fc7f6f to your computer and use it in GitHub Desktop.
Save sword-jin/4412e17b5c3285fc7f6f to your computer and use it in GitHub Desktop.
CSRF token simple class
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