$_SERVER['REMOTE_ADDR'] ?? '', 'script'=>$_SERVER['SCRIPT_NAME'] ?? '']); } else { // Normal operation: create website session (should be set after proper auth) // In final mode, preserve username but do not fabricate IDs. The site should set website_user_id after proper registration/login. $_SESSION['website_username'] = $username; $_SESSION['website_login_time'] = time(); // Try to resolve an existing panel user_id by username so the menu and admin checks work. $resolved_uid = null; if ($db) { $safe = mysqli_real_escape_string($db, $username); $res = @mysqli_query($db, "SELECT user_id FROM {$table_prefix}users WHERE users_login = '$safe' LIMIT 1"); if ($res && mysqli_num_rows($res) === 1) { $r = mysqli_fetch_assoc($res); $resolved_uid = intval($r['user_id'] ?? 0); } } if (!empty($resolved_uid)) { $_SESSION['website_user_id'] = $resolved_uid; } else { // Fallback: assign a numeric session id so the menu treats the user as logged in during debugging $_SESSION['website_user_id'] = time(); } site_log_info('login_success', ['username'=>$username, 'ip'=>$_SERVER['REMOTE_ADDR'] ?? '']); // Always redirect to index.php under site root header('Location: ' . $SITE_ROOT_PATH . '/index.php'); exit(); } } // Close database connection mysqli_close($db); ?>