getToken() !== null) { return hash_equals($token, $this->getToken()); } return false; } /** * Set csrf token cookie * * @param $token */ public function setToken($token) { setcookie(static::CSRF_KEY, $token, time() + 60 * 120, '/'); } /** * Get csrf token * @return string|null */ public function getToken() { if ($this->hasToken()) { return $_COOKIE[static::CSRF_KEY]; } return null; } /** * Returns whether the csrf token has been defined * @return bool */ public function hasToken() { return isset($_COOKIE[static::CSRF_KEY]); } }