7200, 'path' => '/', 'domain' => '', // Specify your domain if needed 'secure' => $secure, 'httponly' => true, 'samesite' => 'Lax' ]; session_set_cookie_params($cookieParams); ini_set('session.gc_maxlifetime', 7200); session_start(); // Generate CSRF token if not already set. if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } // Auto-login via persistent token if session is not active. if (!isset($_SESSION["authenticated"]) && isset($_COOKIE['remember_me_token'])) { $persistentTokensFile = USERS_DIR . 'persistent_tokens.json'; $persistentTokens = []; if (file_exists($persistentTokensFile)) { $encryptedContent = file_get_contents($persistentTokensFile); $decryptedContent = decryptData($encryptedContent, $encryptionKey); $persistentTokens = json_decode($decryptedContent, true); if (!is_array($persistentTokens)) { $persistentTokens = []; } } if (is_array($persistentTokens) && isset($persistentTokens[$_COOKIE['remember_me_token']])) { $tokenData = $persistentTokens[$_COOKIE['remember_me_token']]; if ($tokenData['expiry'] >= time()) { // Token is valid; auto-authenticate the user. $_SESSION["authenticated"] = true; $_SESSION["username"] = $tokenData["username"]; $_SESSION["isAdmin"] = $tokenData["isAdmin"]; // Restore admin status from the token } else { // Token expired; remove it and clear the cookie. unset($persistentTokens[$_COOKIE['remember_me_token']]); $newEncryptedContent = encryptData(json_encode($persistentTokens, JSON_PRETTY_PRINT), $encryptionKey); file_put_contents($persistentTokensFile, $newEncryptedContent, LOCK_EX); setcookie('remember_me_token', '', time() - 3600, '/', '', $secure, true); } } } // Define BASE_URL (this should point to where index.html is, e.g. your uploads directory) define('BASE_URL', 'http://yourwebsite/uploads/'); // If BASE_URL is still the default placeholder, use the server's HTTP_HOST. // Otherwise, use BASE_URL and append share.php. if (strpos(BASE_URL, 'yourwebsite') !== false) { $defaultShareUrl = isset($_SERVER['HTTP_HOST']) ? "http://" . $_SERVER['HTTP_HOST'] . "/share.php" : "http://localhost/share.php"; } else { $defaultShareUrl = rtrim(BASE_URL, '/') . "/share.php"; } define('SHARE_URL', getenv('SHARE_URL') ? getenv('SHARE_URL') : $defaultShareUrl); ?>