- if ($user) {
- $value = json_encode([
- "uid" => $user["uid"],
- "hash" => self::getCookieHashForUser($user),
- "ip" => ($_SERVER['REMOTE_ADDR'] ?? '') ?: '0.0.0.0'
- ]);
- } else {
- $value = "";
- }
-
- setcookie("Friendica", $value, $time, "/", "", (Config::get('system', 'ssl_policy') == App\BaseURL::SSL_POLICY_FULL), true);
- }
-
- /**
- * @brief Checks if the "Friendica" cookie is set
- *
- * @param string $hash
- * @param array $user Record from "user" table
- *
- * @return boolean True, if the cookie is set
- *
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
- public static function checkCookie(string $hash, array $user)
- {
- return hash_equals(
- self::getCookieHashForUser($user),
- $hash
- );
- }
-
- /**
- * @brief Kills the "Friendica" cookie and all session data
- */
- public static function delete()
- {
- self::setCookie(-3600); // make sure cookie is deleted on browser close, as a security measure
- session_unset();
- session_destroy();