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 @@
+
--
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: ';
foreach ($errors as $err) {
- echo '- ' . $err . '
';
+ $errstr .= '- ' . $err . '
';
}
- echo '
';
+ $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: ';
foreach ($errors as $err) {
- echo '- ' . $err . '
';
+ $errstr .= '- ' . $err . '
';
}
- echo '
';
+ $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
';
?>