What's the best way to secure a GET request or are there any, safer alternatives?
I'm using a couple of GET requests in my website to generate webpages dynamically and to delete records based on ID.
The last one worries me a bit, because people could just change the URL to whatever file they want to delete.
To have access to the delete-file they do need to login and have certain permissions, which will throw an error if they don't have sufficient permissions.
I came across a really old SO post, stating that you should use themysqli_real_escape_string
function to make it at least more secure.
I also read about validation being really important, so I was thinking about checking whether the ID is an actual integer or not.
There's another post stating that hiding the request in the URL is basically useless, since the request will always be a part of the URL.
This is my delete-file, it uses two statements, one deletes the actual post, and the other one deletes the associated images with that post.
include('./utils/auth.php');
require('./utils/db.php');
$stmt_1 = $connect->prepare('DELETE FROM `dias` WHERE diaserie_id = ?');
if($stmt_1) {
$id = $_GET['id'];
$stmt_1->bind_param('i', $id);
if($stmt_1->execute()) {
// Als de afbeeldingen uit de database zijn, verwijder dan ook de serie zelf
$stmt_2 = $connect->prepare('DELETE FROM `diaseries` WHERE diaserie_id = ?');
if($stmt_2) {
$stmt_2->bind_param('i', $id);
if($stmt_2->execute()) {
echo "Both the files and post have been deleted.";
} else {
echo "The files have been deleted, the post iself could not be deleted.";
}
}
} else {
echo "Files and post could not be deleted.";
}
}