format(DateTimeInterface::ATOM); $ip = $_SERVER['REMOTE_ADDR'] ?? '-'; $ua = $_SERVER['HTTP_USER_AGENT'] ?? '-'; $line = $ts . ';' . $username . ';' . $ip . ';' . str_replace("\n", ' ', $ua) . "\n"; @file_put_contents(SW_MANUAL_LOG_FILE, $line, FILE_APPEND | LOCK_EX); } function sw_last_login_for_user(string $username): ?DateTimeImmutable { if (!file_exists(SW_MANUAL_LOG_FILE)) { return null; } $fh = @fopen(SW_MANUAL_LOG_FILE, 'r'); if (!$fh) { return null; } $last = null; while (($line = fgets($fh)) !== false) { $parts = explode(';', trim($line)); if (count($parts) < 2) { continue; } [$ts, $user] = $parts; if ($user !== $username) { continue; } try { $dt = new DateTimeImmutable($ts); if ($last === null || $dt > $last) { $last = $dt; } } catch (Exception $e) { continue; } } fclose($fh); return $last; } function sw_format_dt(?DateTimeImmutable $dt): string { if ($dt === null) { return '–'; } return $dt->setTimezone(new DateTimeZone('Europe/Berlin'))->format('d.m.Y, H:i \U\h\r'); }