Fix HTTP 500 on PHP < 8.2: drop standalone true union type
registerUser() declared `: string|true`; the bare `true` type requires PHP 8.2, so including auth.php was a fatal error on PHP 8.0/8.1 — every login/API call returned 500 while install.php (which doesn't include auth.php) worked. Use string|bool instead. Also install a JSON exception handler so future server errors surface a message to the SPA instead of a blank 500. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# CourseHub
|
||||
|
||||
Self-hosted course video player: PHP 8 + MySQL/MariaDB + Bootstrap 5 + [Plyr](https://github.com/sampotts/plyr).
|
||||
Self-hosted course video player: PHP 8.0+ + MySQL/MariaDB + Bootstrap 5 + [Plyr](https://github.com/sampotts/plyr).
|
||||
|
||||
Single-page app: `index.php` is a static shell; all navigation, login, browsing,
|
||||
playback, and scanning happen over AJAX against the JSON API in `api/`
|
||||
|
||||
+2
-1
@@ -51,7 +51,8 @@ function attemptLogin(string $username, string $password): bool
|
||||
return false;
|
||||
}
|
||||
|
||||
function registerUser(string $username, string $password): string|true
|
||||
/** Returns true on success, or an error-message string. */
|
||||
function registerUser(string $username, string $password): string|bool
|
||||
{
|
||||
if (!preg_match('/^[A-Za-z0-9_.-]{3,50}$/', $username)) {
|
||||
return 'Username must be 3-50 characters (letters, digits, _ . -).';
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config.php';
|
||||
|
||||
// Uncaught exceptions in web requests become JSON errors (the SPA surfaces
|
||||
// them) instead of blank 500 pages; details still go to the PHP error log.
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
set_exception_handler(function (Throwable $e): void {
|
||||
error_log($e);
|
||||
http_response_code(500);
|
||||
if (!headers_sent()) {
|
||||
header('Content-Type: application/json');
|
||||
}
|
||||
echo json_encode(['error' => 'Server error: ' . $e->getMessage()]);
|
||||
});
|
||||
}
|
||||
|
||||
function db(): PDO
|
||||
{
|
||||
static $pdo = null;
|
||||
|
||||
Reference in New Issue
Block a user