Update deleteArticle-controller.php
This commit is contained in:
@@ -4,6 +4,7 @@ if (session_status() === PHP_SESSION_NONE) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require_once __DIR__ . "/../model/ArticleManager.php";
|
require_once __DIR__ . "/../model/ArticleManager.php";
|
||||||
|
require_once __DIR__ . "/../../includes/csrf.php";
|
||||||
|
|
||||||
if (!isset($_SESSION["user"])) {
|
if (!isset($_SESSION["user"])) {
|
||||||
header("Location: index.php?pfad=login");
|
header("Location: index.php?pfad=login");
|
||||||
@@ -12,6 +13,13 @@ if (!isset($_SESSION["user"])) {
|
|||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
|
|
||||||
|
// CSRF-Token prüfen, bevor irgendeine Änderung vorgenommen wird
|
||||||
|
if (!csrf_verify()) {
|
||||||
|
$_SESSION["message"] = "invalid_csrf_token";
|
||||||
|
header("location: ../../index.php?pfad=profile");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_SESSION["user_email"])) {
|
if (isset($_SESSION["user_email"])) {
|
||||||
$user = $_SESSION["user_email"];
|
$user = $_SESSION["user_email"];
|
||||||
} else {
|
} else {
|
||||||
@@ -22,9 +30,10 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST["id"]) && !empty($_POST["id"])) {
|
// Die Beitrags-ID muss eine gültige numerische ID sein.
|
||||||
$id = $_POST["id"];
|
$id = filter_input(INPUT_POST, "id", FILTER_VALIDATE_INT);
|
||||||
} else {
|
|
||||||
|
if ($id === false || $id === null) {
|
||||||
$_SESSION["message"] = "missing_id";
|
$_SESSION["message"] = "missing_id";
|
||||||
header("location: ../../index.php?pfad=profile");
|
header("location: ../../index.php?pfad=profile");
|
||||||
exit();
|
exit();
|
||||||
@@ -44,4 +53,4 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
$_SESSION["message"] = "article_deleted";
|
$_SESSION["message"] = "article_deleted";
|
||||||
header("location: ../../index.php?pfad=profile");
|
header("location: ../../index.php?pfad=profile");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user