我正在创建一个网站,用户需要能够上传图片,我希望他们能够删除这些图片。现在,我有一个页面,将显示该用户上传的所有图像,并且我设置了一个php来删除数据库中的图像。它只需要给出图像的ID。我使用GET方法运行,但我担心用户可以找到我的删除PHP的URL,并随机放入ids,删除所有人的图像。有没有一种方法可以调整我的代码以使其更安全?使用GET方法从数据库中删除信息安全吗?
<?php
$sql = "SELECT id, userid, name, image FROM images";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
if ($imageUser == $row["userid"]){
echo "<tr>";
echo "<th>".$row["userid"]."</th>";
echo "<th>".$row["name"]."</th>";
echo "<th><img src='showimage.php?id=".$row["id"]."'></th>";
echo "<th><a href='imgdelete.php?id=".$row["id"]."'>delete</a></th>";
echo "</tr>";
}
}
} else {
echo "0 results";
}
?>
delete.php简单地删除条目WHERE id = $ _ GET ['id'];
用户登录\密码系统将usuall方法 – nogad
检查[此答案](http://stackoverflow.com/questions/10519064/why-is-using-a-http-get-to-update-state-解释为什么要用post而不是 – Stormhashe
你应该使用post ... post也是一种安全的方法...你可以阅读一些关于它的内容: https://stormpath.com/blog/put-or-post – Hackerman