From ba6b8d9e6bf0e27d1254950ecf0332ee8b4f321c Mon Sep 17 00:00:00 2001 From: Frank Harris Date: Mon, 10 Nov 2025 07:23:01 -0500 Subject: [PATCH] Fix tableprefix and cart mysql --- .cpanel.yml | 5 ++ modules/billing/add_to_cart.php | 2 +- modules/billing/admin_invoices.php | 2 +- modules/billing/adminserverlist.php | 8 +- modules/billing/bootstrap.php | 114 +++++++++++++++++++++++++ modules/billing/cart.php | 5 +- modules/billing/check_table.php | 4 +- modules/billing/forgot_password.php | 4 +- modules/billing/includes/menu.php | 6 +- modules/billing/login.php | 8 +- modules/billing/my_account.php | 4 +- modules/billing/my_servers.php | 6 +- modules/billing/order.php | 6 +- modules/billing/register.php | 2 +- modules/billing/renew_server.php | 4 +- modules/billing/reset_password.php | 4 +- modules/billing/server_status.php | 6 +- modules/billing/serverlist.php | 6 +- modules/billing/test_db_connection.php | 4 +- 19 files changed, 161 insertions(+), 39 deletions(-) create mode 100644 .cpanel.yml create mode 100644 modules/billing/bootstrap.php diff --git a/.cpanel.yml b/.cpanel.yml new file mode 100644 index 00000000..18aaebc6 --- /dev/null +++ b/.cpanel.yml @@ -0,0 +1,5 @@ +--- +deployment: + tasks: + - export DEPLOYPATH=/home/domainpl/gameservers.world/ + - /bin/cp -a * $DEPLOYPATH \ No newline at end of file diff --git a/modules/billing/add_to_cart.php b/modules/billing/add_to_cart.php index 3101e688..1e5149f2 100644 --- a/modules/billing/add_to_cart.php +++ b/modules/billing/add_to_cart.php @@ -1,7 +1,7 @@ diff --git a/modules/billing/bootstrap.php b/modules/billing/bootstrap.php new file mode 100644 index 00000000..a612910a --- /dev/null +++ b/modules/billing/bootstrap.php @@ -0,0 +1,114 @@ +real_escape_string((string)$v); + } + return addslashes((string)$v); + } +} + +if (!function_exists('fetch_all_assoc')) { + function fetch_all_assoc($db, $sql) + { + if (!($db instanceof mysqli)) return []; + $res = $db->query($sql); + return $res ? $res->fetch_all(MYSQLI_ASSOC) : []; + } +} + +if (!function_exists('col_exists')) { + function col_exists($db, $table, $col) + { + if (!($db instanceof mysqli)) return false; + $t = $db->real_escape_string($table); + $c = $db->real_escape_string($col); + $res = $db->query("SHOW COLUMNS FROM `{$t}` LIKE '{$c}'"); + return ($res && $res->num_rows > 0); + } +} + +// expose a convenience variable for scripts that expect $db +// Do not overwrite an existing $db if present +if (!isset($db) || !($db instanceof mysqli)) { + $maybe = billing_get_db(); + if ($maybe instanceof mysqli) { + $db = $maybe; + } +} + +// End bootstrap diff --git a/modules/billing/cart.php b/modules/billing/cart.php index b0ea58be..f0fe8183 100644 --- a/modules/billing/cart.php +++ b/modules/billing/cart.php @@ -40,7 +40,7 @@ if (session_status() === PHP_SESSION_NONE) { } // Load configuration -require_once(__DIR__ . '/includes/config.inc.php'); +require_once(__DIR__ . '/bootstrap.php'); // Check if user is logged in $user_id = 0; @@ -231,8 +231,7 @@ $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https: $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; $siteBase = $protocol . $host; -// Close database connection -mysqli_close($db); +// (Do not close the shared DB connection here; menu and other includes may use it.) ?> diff --git a/modules/billing/check_table.php b/modules/billing/check_table.php index 28f91033..48696516 100644 --- a/modules/billing/check_table.php +++ b/modules/billing/check_table.php @@ -3,7 +3,7 @@ * Check {table_prefix}billing_invoices table structure */ -require_once('../../includes/config.inc.php'); +require_once(__DIR__ . '/bootstrap.php'); require_once('../../includes/database_mysqli.php'); $db = createDatabaseConnection($db_host, $db_user, $db_pass, $db_name, $db_port); @@ -72,5 +72,5 @@ if (mysqli_num_rows($last_result) > 0) { echo "

No invoices found.

\n"; } -mysqli_close($db); + billing_maybe_close_db($db); ?> diff --git a/modules/billing/forgot_password.php b/modules/billing/forgot_password.php index 5e64fc97..c10e2d89 100644 --- a/modules/billing/forgot_password.php +++ b/modules/billing/forgot_password.php @@ -4,7 +4,7 @@ session_name("gameservers_website"); session_start(); // Include database configuration -require_once(__DIR__ . '/includes/config.inc.php'); +require_once(__DIR__ . '/bootstrap.php'); // Create database connection $db = mysqli_connect($db_host, $db_user, $db_pass, $db_name); @@ -109,7 +109,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['request_reset'])) { } // Close database connection -mysqli_close($db); + billing_maybe_close_db($db); ?> diff --git a/modules/billing/includes/menu.php b/modules/billing/includes/menu.php index b5bc61c4..e5067d7d 100644 --- a/modules/billing/includes/menu.php +++ b/modules/billing/includes/menu.php @@ -50,7 +50,11 @@ if ($is_logged_in) { } } if ($menu_db_opened) { - mysqli_close($menu_db); + if (function_exists('billing_maybe_close_db')) { + billing_maybe_close_db($menu_db); + } else { + @mysqli_close($menu_db); + } } } } diff --git a/modules/billing/login.php b/modules/billing/login.php index 6ca5a697..664ad83b 100644 --- a/modules/billing/login.php +++ b/modules/billing/login.php @@ -9,8 +9,8 @@ error_reporting(E_ALL); // We'll compute a site root below (up to /_website) and define a strict sanitizer after config is loaded -// Include database configuration -require_once(__DIR__ . '/includes/config.inc.php'); +// Include billing bootstrap (loads database configuration) +require_once(__DIR__ . '/bootstrap.php'); require_once(__DIR__ . '/includes/log.php'); // Determine site root up to /_website so we can enforce absolute redirects within this site @@ -97,8 +97,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) { } } -// Close database connection -mysqli_close($db); +// Keep DB connection open for includes (menu.php may query the DB). The +// connection lifecycle is handled centrally; avoid closing here. ?> diff --git a/modules/billing/my_account.php b/modules/billing/my_account.php index 7432bc5e..20636d78 100644 --- a/modules/billing/my_account.php +++ b/modules/billing/my_account.php @@ -28,7 +28,7 @@ if (!$is_logged_in) { } // Include database configuration -require_once(__DIR__ . '/includes/config.inc.php'); +require_once(__DIR__ . '/bootstrap.php'); // Create database connection $db = mysqli_connect($db_host, $db_user, $db_pass, $db_name); @@ -379,7 +379,7 @@ $status_config = [ diff --git a/modules/billing/my_servers.php b/modules/billing/my_servers.php index 26502637..9dbb8a9f 100644 --- a/modules/billing/my_servers.php +++ b/modules/billing/my_servers.php @@ -10,8 +10,8 @@ // Require login for this page require_once(__DIR__ . '/includes/login_required.php'); -// Include database configuration -require_once(__DIR__ . '/includes/config.inc.php'); +// Include billing bootstrap (loads config and DB helper) +require_once(__DIR__ . '/bootstrap.php'); // Create database connection $db = mysqli_connect($db_host, $db_user, $db_pass, $db_name); @@ -136,7 +136,7 @@ $result = mysqli_query($db, $query); diff --git a/modules/billing/order.php b/modules/billing/order.php index ddcee005..319f247c 100644 --- a/modules/billing/order.php +++ b/modules/billing/order.php @@ -23,8 +23,8 @@ This method means we can use one code block in every game page and fill in the d // Require login for ordering require_once(__DIR__ . '/includes/login_required.php'); -// Include database configuration -require_once(__DIR__ . '/includes/config.inc.php'); +// Include billing bootstrap (loads config and DB helper) +require_once(__DIR__ . '/bootstrap.php'); // Create database connection $db = mysqli_connect($db_host, $db_user, $db_pass, $db_name); @@ -308,7 +308,7 @@ if ($row['price_monthly'] == 0.0) { diff --git a/modules/billing/register.php b/modules/billing/register.php index 5492002e..d7282dd1 100644 --- a/modules/billing/register.php +++ b/modules/billing/register.php @@ -1,7 +1,7 @@ diff --git a/modules/billing/reset_password.php b/modules/billing/reset_password.php index 420107fa..71962c37 100644 --- a/modules/billing/reset_password.php +++ b/modules/billing/reset_password.php @@ -4,7 +4,7 @@ session_name("gameservers_website"); session_start(); // Include database configuration -require_once(__DIR__ . '/includes/config.inc.php'); +require_once(__DIR__ . '/bootstrap.php'); // Create database connection $db = mysqli_connect($db_host, $db_user, $db_pass, $db_name); @@ -105,7 +105,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['reset_password']) && } // Close database connection -mysqli_close($db); + billing_maybe_close_db($db); ?> diff --git a/modules/billing/server_status.php b/modules/billing/server_status.php index 0eb87b91..96fced3a 100644 --- a/modules/billing/server_status.php +++ b/modules/billing/server_status.php @@ -7,8 +7,8 @@ diff --git a/modules/billing/serverlist.php b/modules/billing/serverlist.php index 6bb4f3af..fb61fa26 100644 --- a/modules/billing/serverlist.php +++ b/modules/billing/serverlist.php @@ -12,7 +12,7 @@ ini_set('display_startup_errors', 1); error_reporting(E_ALL); // Include database configuration -require_once(__DIR__ . '/includes/config.inc.php'); +require_once(__DIR__ . '/bootstrap.php'); // Create database connection $db = mysqli_connect($db_host, $db_user, $db_pass, $db_name); @@ -38,7 +38,7 @@ $services = $db->query($qry_services); if (!$services) { echo ""; - mysqli_close($db); + billing_maybe_close_db($db); return; } @@ -123,7 +123,7 @@ include(__DIR__ . '/includes/menu.php'); diff --git a/modules/billing/test_db_connection.php b/modules/billing/test_db_connection.php index bc8cbe21..cd694c9a 100644 --- a/modules/billing/test_db_connection.php +++ b/modules/billing/test_db_connection.php @@ -10,8 +10,8 @@ * accessible in production. */ -// Include database configuration -require_once(__DIR__ . '/includes/config.inc.php'); +// Include billing bootstrap (loads config and DB helper) +require_once(__DIR__ . '/bootstrap.php'); // Create database connection $db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);