summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcflip <36554078+cflip@users.noreply.github.com>2021-03-25 19:57:42 -0600
committercflip <36554078+cflip@users.noreply.github.com>2021-03-25 19:57:42 -0600
commitd4a657334d4100c29a700d21e05b5e7fef8fce64 (patch)
tree031508ff1ab34820dceceb7ae2a7e772db6fbf5e
parent0ecae4e72d7d4ace51b731ff2c5d5eb63351e3e1 (diff)
Create 404 page for invalid ids
-rw-r--r--category.php10
-rw-r--r--model/Category.php3
-rw-r--r--model/Thread.php3
-rw-r--r--templates/404.php11
-rw-r--r--thread.php10
5 files changed, 33 insertions, 4 deletions
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();
+ }
}
?>
<!DOCTYPE html>
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 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>cflip.net forum</title>
+</head>
+<body>
+ <?php include_once 'header.php'; ?>
+ <h1>Page Not Found</h1>
+ <p>The page you requested does not exist.</p>
+</body>
+</html> \ 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();
+ }
}
?>
<!DOCTYPE html>