I get an id via Get request to fetch an object from the database.
I have used mysqli prepared statements to avoid any security problems. As I am new to these stuff I would like a confirmation that implemented the logic correctly and safe.
User goes to
website.com/post.php?post=130
In post.php i do the following:
Check if user sent a value in "post" parameter, otherwise redirect to the start page:
if(strlen($_GET["post"]) == 0){
header("Location: index.php");
exit();
}
then i use the paramter to fetch the object from the database:
$requestedID = $_GET["post"];
if(is_numeric($requestedID)){
if($stmt = $mysqli->prepare("SELECT * FROM posts WHERE id =?")) {
$stmt->bind_param('s', $requestedID);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows > 0) {
$row = $result->fetch_assoc();
// logic for the content
}else{
header("Location: index.php");
exit();
}
} else {
header("Location: index.php");
exit();
}
}else {
header("Location: index.php");
exit();
}
Is my mysqli code secure? Is my handling of GET parameter secure enough? Do you see anything that concerns you?