From 4145fa13230d25d9978c003a8cccd1b7c2e11aaf Mon Sep 17 00:00:00 2001 From: h5p9sl <21267024+h5p9sl@users.noreply.github.com> Date: Thu, 13 May 2021 21:02:43 -0600 Subject: Clean up HTML; no functional changes --- includes/templates/header.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/templates/header.php b/includes/templates/header.php index 1db9cda..5070cfe 100644 --- a/includes/templates/header.php +++ b/includes/templates/header.php @@ -1,4 +1,6 @@ +

cflip.net forumbeta

+

[Home] [All Threads] [All Posts] @@ -16,3 +18,5 @@ } ?> +

+
-- cgit v1.2.3 From fe41f57df59c7f2a11d80eaaebf08d3a3a51a6d5 Mon Sep 17 00:00:00 2001 From: h5p9sl <21267024+h5p9sl@users.noreply.github.com> Date: Thu, 13 May 2021 22:07:11 -0600 Subject: Add error handling --- create_thread.php | 4 +++- includes/Session.php | 2 +- includes/error.php | 25 +++++++++++++++++++++++++ register.php | 10 ++++++---- signin.php | 10 ++++++---- signout.php | 2 +- viewthread.php | 19 ++++++++++--------- 7 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 includes/error.php diff --git a/create_thread.php b/create_thread.php index 6fb7df9..a203b39 100644 --- a/create_thread.php +++ b/create_thread.php @@ -10,6 +10,7 @@

Create a new thread

is_signed_in()) { trigger_error('You must be signed in to create a thread.'); exit(); @@ -44,6 +45,7 @@ if (!Session::get()->is_signed_in()) { '. $message .'

'; +} + +function handle_error($errno, $errstr, $errfile, $errline) { + if (!(error_reporting() & $errno)) { + // This error code is not included in error_reporting, so let it fall + // through to the standard PHP error handler + return false; + } + + switch ($errno) { + // See https://www.php.net/manual/en/errorfunc.constants.php + case E_USER_NOTICE: + user_notice($errstr); + break; + default: + return false; + } + return true; +} + +$old_error_handler = set_error_handler('handle_error'); +?> diff --git a/register.php b/register.php index 02fbe58..4c42610 100644 --- a/register.php +++ b/register.php @@ -21,6 +21,7 @@ '; + $errstr = 'Please check the following problems: '; + $errstr .= ''; + trigger_error($errstr); } else { $pass_hash = password_hash($user_pass, PASSWORD_DEFAULT); register_user($user_name, $pass_hash); - echo 'Account successfully registered! You can now sign in'; + echo '

Account successfully registered! You can now sign in

'; } } ?> diff --git a/signin.php b/signin.php index 2c43309..c38845d 100644 --- a/signin.php +++ b/signin.php @@ -17,6 +17,7 @@ '; + $errstr = 'Please check the following problems: '; + $errstr .= ''; + trigger_error($errstr); } else { $user = new User(); $result = $user->get_by_name($user_name); if (!$result) { - echo 'There is no user with that name. Did you mean to create a new account?'; + trigger_error('There is no user with that name. Did you mean to create a new account?'); } else { if (!password_verify($user_pass, $user->password)) { echo 'Password does not match!'; diff --git a/signout.php b/signout.php index 035877b..bbaa47a 100644 --- a/signout.php +++ b/signout.php @@ -13,4 +13,4 @@ include_once './includes/templates/header.php'; echo '

You have now been signed out

'; ?> - \ No newline at end of file + diff --git a/viewthread.php b/viewthread.php index e8eda06..fa1c81b 100644 --- a/viewthread.php +++ b/viewthread.php @@ -68,29 +68,30 @@ foreach ($posts as $post) { ?>

Reply to this thread

-
- -
- -
- - is_signed_in()) { - echo 'You must be signed in to reply to this thread.'; + trigger_error('You must be signed in to reply to this thread.', E_USER_NOTICE); return; } $post_content = filter_input(INPUT_POST, 'post_content', FILTER_SANITIZE_STRING); if (empty($post_content) or !$post_content) { - echo 'Thread subject cannot be empty'; + trigger_error('Reply cannot be empty'); } else { create_post($post_content, $current->id, $current->category->id); header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $current->id); } } ?> +
+ +
+ +
+ + -- cgit v1.2.3 From 2b03ca63d06ec5da45c887ef7cb3daa35a8642f7 Mon Sep 17 00:00:00 2001 From: h5p9sl <21267024+h5p9sl@users.noreply.github.com> Date: Thu, 13 May 2021 22:27:06 -0600 Subject: Disallow empty post content when creating threads --- create_thread.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/create_thread.php b/create_thread.php index a203b39..976bd9f 100644 --- a/create_thread.php +++ b/create_thread.php @@ -27,7 +27,7 @@ if (!Session::get()->is_signed_in()) { $categories = get_all_categories(); if (count($categories) == 0) { - echo 'There are no categories to post to!'; + trigger_error('There are no categories to post to!'); } else { echo '