我会使用这样的东西:
<!DOCTYPE HTML>
<!--
<?php
if(!isset($_GET['id']) && empty(trim($_GET['id']))) die('No post number specified!');
$conn = mysqli_connect('localhost', 'username', 'password', 'blog_db') or die('MySQL connection failed!');
$id = mysqli_real_escape_string($conn, preg_replace('/[^0-9]/', '', $_GET['id'])
$query = "SELECT * FROM `posts` WHERE `id` = '$id'";
$result = mysqli_query($conn, $query) or die('MySQL query failed!');
$post = mysqli_fetch_assoc($result) or die('Fetching content failed!');
$title = $post['title'];
$content = $post['content'];
$tags = explode(',', $post['tags']);
$author = $post['author'];
$time = $post['time'];
?>
-->
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title><?php echo htmlentities($title); ?> — By Blog</title>
<meta name="keywords" content="<?php echo implode(',', htmlentities($tags)); ?>" />
</head>
<body>
<div id="post">
<div id="post-content">
<?php echo htmlentities($post); ?>
</div>
<div id="post-tags">
<ul id="tags">
<?php foreach($tags as $tag) { ?>
<li>
<a href="/tagged/<?php echo urlencode($tag); ?>"><?php echo htmlentities($tag) ?></a>
</li>
<?php } ?>
</ul>
</div>
<div id="author">posted by <a href="/author/<?php echo urlencode($author); ?>"><?php echo htmlentities($author); ?></a></div>
</div>
</body>
</html>
您可能希望研究 URL 重写(查看此 URL:标题可见,但实际文件不存在),这将使其对搜索引擎更加友好。
此外,为访问者提供站点地图也很好,因为搜索引擎也会跟踪那里的链接。