+use Friendica\App;
+use Friendica\Core\Config;
+use Friendica\Core\PConfig;
+use Friendica\Core\System;
+use Friendica\Database\DBM;
+use Friendica\Model\Group;
+
+/**
+ * @brief Calculate the hash that is needed for the "Friendica" cookie
+ *
+ * @param array $user Record from "user" table
+ *
+ * @return string Hashed data
+ */
+function cookie_hash($user)
+{
+ return(hash("sha256", Config::get("system", "site_prvkey") .
+ $user["prvkey"] .
+ $user["password"]));
+}
+
+/**
+ * @brief Set the "Friendica" cookie
+ *
+ * @param int $time
+ * @param array $user Record from "user" table
+ */
+function new_cookie($time, $user = [])
+{
+ if ($time != 0) {
+ $time = $time + time();
+ }
+
+ if ($user) {
+ $value = json_encode(["uid" => $user["uid"],
+ "hash" => cookie_hash($user),
+ "ip" => $_SERVER['REMOTE_ADDR']]);
+ } else {
+ $value = "";
+ }
+
+ setcookie("Friendica", $value, $time, "/", "", (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL), true);
+}