30 lines
745 B
PHP
30 lines
745 B
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'includes/header.php';
|
|
|
|
$slug = $_GET['slug'] ?? null;
|
|
if (!$slug) {
|
|
header('Location: /');
|
|
exit;
|
|
}
|
|
|
|
$stmt = db()->prepare("SELECT posts.*, users.username FROM posts JOIN users ON posts.user_id = users.id WHERE posts.slug = ?");
|
|
$stmt->execute([$slug]);
|
|
$post = $stmt->fetch();
|
|
|
|
if (!$post) {
|
|
http_response_code(404);
|
|
echo "Post not found";
|
|
exit;
|
|
}
|
|
?>
|
|
|
|
<h1><?php echo htmlspecialchars($post['title']); ?></h1>
|
|
<p class="text-muted">By <?php echo htmlspecialchars($post['username']); ?> on <?php echo date('F j, Y', strtotime($post['created_at'])); ?></p>
|
|
|
|
<div>
|
|
<?php echo nl2br(htmlspecialchars($post['content'])); ?>
|
|
</div>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|