34796-vm/page.php
2025-10-08 11:52:31 +00:00

42 lines
1.0 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
$slug = $_GET['slug'] ?? null;
if (!$slug) {
http_response_code(404);
echo "Page not found.";
exit();
}
$stmt = db()->prepare("SELECT * FROM pages WHERE slug = ?");
$stmt->execute([$slug]);
$page = $stmt->fetch();
if (!$page) {
http_response_code(404);
// You can create a more sophisticated 404 page
include 'includes/header.php';
echo "<div class=\"container\"><p>Sorry, the page you are looking for does not exist.</p></div>";
include 'includes/footer.php';
exit();
}
// SEO and page metadata
$page_title = htmlspecialchars($page['title']);
$meta_description = htmlspecialchars(substr(strip_tags($page['content']), 0, 160));
include 'includes/header.php';
?>
<div class="container page-content">
<h1><?php echo htmlspecialchars($page['title']); ?></h1>
<hr>
<div>
<?php echo nl2br(htmlspecialchars($page['content'])); // Using nl2br to respect line breaks, and htmlspecialchars for security ?>
</div>
</div>
<?php
include 'includes/footer.php';