add custom 404 error page with logging and styled response

This commit is contained in:
Fabian Schieder 2026-02-27 22:02:45 +01:00
parent 0ea180c4cc
commit cd8cacc226

102
404.php Normal file
View File

@ -0,0 +1,102 @@
<?php
// Wichtig: echten 404-Status setzen
http_response_code(404);
// Request-Daten absichern
$requestUri = htmlspecialchars($_SERVER['REQUEST_URI'] ?? '', ENT_QUOTES, 'UTF-8');
$method = htmlspecialchars($_SERVER['REQUEST_METHOD'] ?? '', ENT_QUOTES, 'UTF-8');
$ip = htmlspecialchars($_SERVER['REMOTE_ADDR'] ?? '', ENT_QUOTES, 'UTF-8');
// Optional: einfaches Logging
error_log("[404] $ip $method $requestUri");
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 Seite nicht gefunden</title>
<style>
:root {
--bg: #0f172a;
--card: #1e293b;
--accent: #3b82f6;
--text: #e2e8f0;
--muted: #94a3b8;
}
body {
margin: 0;
font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
background: linear-gradient(135deg, #0f172a, #1e293b);
color: var(--text);
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.card {
background: var(--card);
padding: 3rem;
border-radius: 16px;
box-shadow: 0 20px 40px rgba(0,0,0,0.4);
max-width: 500px;
width: 90%;
text-align: center;
}
h1 {
font-size: 4rem;
margin: 0;
color: var(--accent);
}
p {
color: var(--muted);
margin: 1rem 0;
}
a {
display: inline-block;
margin-top: 1.5rem;
padding: 0.75rem 1.5rem;
border-radius: 8px;
background: var(--accent);
color: white;
text-decoration: none;
font-weight: 600;
transition: 0.2s ease;
}
a:hover {
background: #2563eb;
transform: translateY(-2px);
}
.footer {
margin-top: 2rem;
font-size: 0.8rem;
color: #64748b;
}
</style>
</head>
<body>
<div class="card">
<h1>404</h1>
<p>Die angeforderte Seite wurde nicht gefunden.</p>
<p><strong><?php echo $requestUri; ?></strong></p>
<a href="/">Zur Startseite</a>
<div class="footer">
Anfrage: <?php echo $method; ?> <br>
Server: fabianschieder.com
</div>
</div>
</body>
</html>