fix(platform-tools): renomeia $user em config/db.php para não colidir com o router

O router (platform.php) requer config/db.php e as páginas partilhadas no
mesmo âmbito plano, sem função a separar — o $user = env('DB_USER')
(a string do utilizador da BD) ficava visível mais tarde em
includes/header.php, que só substitui $user quando está vazio
($user ?? current_user() ?? …). O utilizador de sessão nunca entrava,
e $user['role'] rebentava com TypeError "Cannot access offset of type
string on string" em todas as páginas de sistema (Backups, Auditoria,
Actualizações, IP bans, Origem das visitas) — só a Geo escapava por não
usar esse layout. Confirmado em logs/php_errors.jsonl em produção.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
andreandClaude Sonnet 5 committed 2026-09-25 12:25:40 +01:00
1 parent f066eec7c7
commit 35415429e5
1 file changed
+9 -6
+9 -6
View File
@@ -40,16 +40,19 @@ if (getenv('DB_PASS') === false) {
_bootstrap_fail('required env var DB_PASS is not set (empty string is allowed)'); _bootstrap_fail('required env var DB_PASS is not set (empty string is allowed)');
} }
$host = env('DB_HOST', '127.0.0.1'); $host = env('DB_HOST', '127.0.0.1');
$port = (int) env('DB_PORT', 3306); $port = (int) env('DB_PORT', 3306);
$db = env('DB_NAME'); $db = env('DB_NAME');
$user = env('DB_USER'); // Not $user: that name leaks into the router's flat include scope (router.php
$pass = env('DB_PASS'); // requires this file at top level, no function wrapper) and would shadow the
// real logged-in user array that includes/header.php expects.
$dbUser = env('DB_USER');
$pass = env('DB_PASS');
$dsn = "mysql:host=$host;port=$port;dbname=$db;charset=utf8mb4"; $dsn = "mysql:host=$host;port=$port;dbname=$db;charset=utf8mb4";
try { try {
$pdo = new PDO($dsn, $user, $pass, [ $pdo = new PDO($dsn, $dbUser, $pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
// Real server-side prepares (not driver emulation): a tighter defence // Real server-side prepares (not driver emulation): a tighter defence
// against injection than emulated string-interpolation. Safe here — the // against injection than emulated string-interpolation. Safe here — the