From d4a657334d4100c29a700d21e05b5e7fef8fce64 Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Thu, 25 Mar 2021 19:57:42 -0600 Subject: Create 404 page for invalid ids --- category.php | 10 +++++++++- model/Category.php | 3 ++- model/Thread.php | 3 ++- templates/404.php | 11 +++++++++++ thread.php | 10 +++++++++- 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 templates/404.php diff --git a/category.php b/category.php index ad4faa6..b149237 100644 --- a/category.php +++ b/category.php @@ -7,8 +7,16 @@ session_start(); $current = new Category(); if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) { + http_response_code(404); + include_once 'templates/404.php'; + die(); } else { - $current->get_from_database($_GET['id'], $dbc); + $result = $current->get_from_database($_GET['id'], $dbc); + if ($result == 0) { + http_response_code(404); + include_once 'templates/404.php'; + die(); + } } ?> diff --git a/model/Category.php b/model/Category.php index 5a2c11c..1b699fb 100644 --- a/model/Category.php +++ b/model/Category.php @@ -18,7 +18,7 @@ class Category { } if (mysqli_num_rows($result) == 0) { - echo 'Category does not exist!'; + return 0; } else { while ($row = mysqli_fetch_assoc($result)) { $this->id = $id; @@ -30,6 +30,7 @@ class Category { } mysqli_free_result($result); + return 1; } function get_threads($dbc) { diff --git a/model/Thread.php b/model/Thread.php index 20c6c0a..aa48cfd 100644 --- a/model/Thread.php +++ b/model/Thread.php @@ -21,7 +21,7 @@ class Thread { } if (mysqli_num_rows($result) == 0) { - + return 0; } else { while ($row = mysqli_fetch_assoc($result)) { $this->id = $id; @@ -38,6 +38,7 @@ class Thread { } mysqli_free_result($result); + return 1; } function get_posts($dbc) { diff --git a/templates/404.php b/templates/404.php new file mode 100644 index 0000000..9ba4bcc --- /dev/null +++ b/templates/404.php @@ -0,0 +1,11 @@ + + +
+The page you requested does not exist.
+ + \ No newline at end of file diff --git a/thread.php b/thread.php index 0d516da..f784e40 100644 --- a/thread.php +++ b/thread.php @@ -7,8 +7,16 @@ session_start(); $current = new Thread(); if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) { + http_response_code(404); + include_once 'templates/404.php'; + die(); } else { - $current->get_from_database($_GET['id'], $dbc); + $result = $current->get_from_database($_GET['id'], $dbc); + if ($result == 0) { + http_response_code(404); + include_once 'templates/404.php'; + die(); + } } ?> -- cgit v1.2.3