所以,我是PHP和SQL的初学者。我正在创建一个简单的博客。我有index.php,在那里发布博客和blog.php,它显示博客文章。我希望能够在blog.php上的每篇博文中添加一个编辑链接。一旦你点击这个编辑链接,你可以在另一个页面上编辑博客。我想知道什么是最安全的方法,而不使用框架。这里是blog.php的代码:安全地编辑博客文章
<?php include("session_start.php")?>
<?php
$sql = "SELECT * FROM posts WHERE user_name='$user_name' ORDER BY post_date DESC";
$result = mysqli_query($connection, $sql) or die(mysqli_error($connection));
?>
<html>
<head>
<title>Blog</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >
<link rel="stylesheet" href="styles.css" >
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="align-right">
<a href='index.php'>Post a Blog</a> | <a href='account_settings.php'>Account Settings</a> | <a href='logout.php' onclick="return confirm('Are you sure?')">Logout</a>
</div>
<h1>Blog</h1>
<?php
while($column = mysqli_fetch_assoc($result)){
?>
<h2><?php echo $column["post_title"]?></h2>
<div class="view-post-content"><?php echo $column["post_content"]?></div>
<p class="category">Category: <?php echo $column["post_category"]?></p>
<p>This post was written <?php echo $column["post_date"]?>.</p>
<?php
}
?>
</div>
</div>
</body>
</html>
<?php include "footer.php";?>
你在你的PHP应用程序的任何类型的用户身份验证设置的?这可能是第一个开始的地方。在博客文章的每个请求中,PHP会验证用户是谁,他说他是谁,他有权读取/编辑/删除给定的帖子等。 –
如果我们谈论“安全的方式”,那么它的一个广泛的问题。但如果你只需要编辑博客文章,只需发送博客文章ID到编辑页面,并通过其ID从数据库获取博客数据。 – arisalsaila
但是不发送博客ID有点不安全,因为其他人可以猜测这些ID访问页面? – Julian