+use Friendica\App;
+
+/**
+ * @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", get_config("system", "site_prvkey").
+ $user["uprvkey"].
+ $user["password"]));
+}
+
+/**
+ * @brief Set the "Friendica" cookie
+ *
+ * @param int $time
+ * @param array $user Record from "user" table
+ */
+function new_cookie($time, $user = array()) {
+
+ if ($time != 0) {
+ $time = $time + time();
+ }
+
+ if ($user) {
+ $value = json_encode(array("uid" => $user["uid"],
+ "hash" => cookie_hash($user),
+ "ip" => $_SERVER['REMOTE_ADDR']));
+ }
+ else {
+ $value = "";
+ }
+
+ setcookie("Friendica", $value, $time, "/", "",
+ (get_config('system', 'ssl_policy') == SSL_POLICY_FULL), true);
+
+}
+