Fix tableprefix and cart mysql
This commit is contained in:
parent
723dd58e71
commit
ba6b8d9e6b
19 changed files with 161 additions and 39 deletions
5
.cpanel.yml
Normal file
5
.cpanel.yml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
deployment:
|
||||||
|
tasks:
|
||||||
|
- export DEPLOYPATH=/home/domainpl/gameservers.world/
|
||||||
|
- /bin/cp -a * $DEPLOYPATH
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// _website/add_to_cart.php
|
// _website/add_to_cart.php
|
||||||
// Handle Add to Cart posts from order.php
|
// Handle Add to Cart posts from order.php
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
require_once(__DIR__ . '/includes/login_required.php');
|
require_once(__DIR__ . '/includes/login_required.php');
|
||||||
require_once(__DIR__ . '/includes/log.php');
|
require_once(__DIR__ . '/includes/log.php');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// Admin invoices viewer and editor
|
// Admin invoices viewer and editor
|
||||||
$session_name = session_name(); session_start();
|
$session_name = session_name(); session_start();
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
require_once(__DIR__ . '/includes/admin_auth.php');
|
require_once(__DIR__ . '/includes/admin_auth.php');
|
||||||
|
|
||||||
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
/* === SITE_BASE_URL is loaded from includes/config.inc.php; leave empty to use relative paths === */
|
/* === SITE_BASE_URL is loaded from includes/config.inc.php; leave empty to use relative paths === */
|
||||||
|
|
||||||
// Include database configuration
|
// Include billing bootstrap (loads config and DB helper)
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Protect this page: require admin
|
// Protect this page: require admin
|
||||||
require_once(__DIR__ . '/includes/admin_auth.php');
|
require_once(__DIR__ . '/includes/admin_auth.php');
|
||||||
|
|
@ -331,8 +331,8 @@ document.querySelectorAll('.locs-box').forEach(function(box){
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// Close database connection
|
// Close database connection safely
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
114
modules/billing/bootstrap.php
Normal file
114
modules/billing/bootstrap.php
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
<?php
|
||||||
|
// modules/billing/bootstrap.php
|
||||||
|
// Central bootstrap for billing website pages. Loads config, provides safe DB helper
|
||||||
|
// and ensures $table_prefix is available.
|
||||||
|
|
||||||
|
// Load configuration (includes/config.inc.php) if present
|
||||||
|
$config_path = __DIR__ . '/includes/config.inc.php';
|
||||||
|
if (file_exists($config_path)) {
|
||||||
|
require_once $config_path;
|
||||||
|
} else {
|
||||||
|
trigger_error('Billing config not found: ' . $config_path, E_USER_WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure $table_prefix exists (fallback to empty string)
|
||||||
|
if (!isset($table_prefix)) {
|
||||||
|
$table_prefix = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Billing DB connection cached in $billing_db
|
||||||
|
if (!isset($billing_db)) {
|
||||||
|
$billing_db = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Track whether bootstrap opened the connection (so callers can safely close it)
|
||||||
|
$billing_db_opened_by_bootstrap = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a mysqli connection for billing pages.
|
||||||
|
* - Reuses global $db if already created by other code.
|
||||||
|
* - Tries to open a new connection using config variables if needed.
|
||||||
|
* - Returns null on failure.
|
||||||
|
*/
|
||||||
|
function billing_get_db()
|
||||||
|
{
|
||||||
|
global $billing_db, $db, $db_host, $db_user, $db_pass, $db_name, $billing_db_opened_by_bootstrap;
|
||||||
|
if (!empty($billing_db) && ($billing_db instanceof mysqli)) {
|
||||||
|
return $billing_db;
|
||||||
|
}
|
||||||
|
if (!empty($db) && ($db instanceof mysqli)) {
|
||||||
|
$billing_db = $db;
|
||||||
|
return $billing_db;
|
||||||
|
}
|
||||||
|
// Try to connect (suppress warnings; caller may check return value)
|
||||||
|
$conn = @mysqli_connect($db_host ?? null, $db_user ?? null, $db_pass ?? null, $db_name ?? null);
|
||||||
|
if ($conn) {
|
||||||
|
// Set charset when available
|
||||||
|
if (function_exists('mysqli_set_charset')) {
|
||||||
|
@mysqli_set_charset($conn, 'utf8mb4');
|
||||||
|
}
|
||||||
|
$billing_db = $conn;
|
||||||
|
$billing_db_opened_by_bootstrap = true;
|
||||||
|
return $billing_db;
|
||||||
|
}
|
||||||
|
// Leave $billing_db as null
|
||||||
|
$billing_db = null;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close DB connection only if it was opened by bootstrap. If the connection
|
||||||
|
* is shared (created by other code) this function will not close it.
|
||||||
|
*/
|
||||||
|
function billing_maybe_close_db($conn)
|
||||||
|
{
|
||||||
|
global $billing_db, $billing_db_opened_by_bootstrap;
|
||||||
|
if (!($conn instanceof mysqli)) return;
|
||||||
|
if (!empty($billing_db_opened_by_bootstrap) && $billing_db === $conn) {
|
||||||
|
@mysqli_close($conn);
|
||||||
|
$billing_db = null;
|
||||||
|
$billing_db_opened_by_bootstrap = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Small helper wrappers commonly used across billing pages
|
||||||
|
if (!function_exists('esc_mysqli')) {
|
||||||
|
function esc_mysqli($db, $v)
|
||||||
|
{
|
||||||
|
if ($db instanceof mysqli) {
|
||||||
|
return $db->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
|
||||||
|
|
@ -40,7 +40,7 @@ if (session_status() === PHP_SESSION_NONE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load configuration
|
// Load configuration
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Check if user is logged in
|
// Check if user is logged in
|
||||||
$user_id = 0;
|
$user_id = 0;
|
||||||
|
|
@ -231,8 +231,7 @@ $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https:
|
||||||
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
||||||
$siteBase = $protocol . $host;
|
$siteBase = $protocol . $host;
|
||||||
|
|
||||||
// Close database connection
|
// (Do not close the shared DB connection here; menu and other includes may use it.)
|
||||||
mysqli_close($db);
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* Check {table_prefix}billing_invoices table structure
|
* Check {table_prefix}billing_invoices table structure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once('../../includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
require_once('../../includes/database_mysqli.php');
|
require_once('../../includes/database_mysqli.php');
|
||||||
|
|
||||||
$db = createDatabaseConnection($db_host, $db_user, $db_pass, $db_name, $db_port);
|
$db = createDatabaseConnection($db_host, $db_user, $db_pass, $db_name, $db_port);
|
||||||
|
|
@ -72,5 +72,5 @@ if (mysqli_num_rows($last_result) > 0) {
|
||||||
echo "<p>No invoices found.</p>\n";
|
echo "<p>No invoices found.</p>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ session_name("gameservers_website");
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
// Include database configuration
|
// Include database configuration
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Create database connection
|
// Create database connection
|
||||||
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
$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
|
// Close database connection
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,11 @@ if ($is_logged_in) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($menu_db_opened) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
// We'll compute a site root below (up to /_website) and define a strict sanitizer after config is loaded
|
||||||
|
|
||||||
// Include database configuration
|
// Include billing bootstrap (loads database configuration)
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
require_once(__DIR__ . '/includes/log.php');
|
require_once(__DIR__ . '/includes/log.php');
|
||||||
|
|
||||||
// Determine site root up to /_website so we can enforce absolute redirects within this site
|
// 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
|
// Keep DB connection open for includes (menu.php may query the DB). The
|
||||||
mysqli_close($db);
|
// connection lifecycle is handled centrally; avoid closing here.
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ if (!$is_logged_in) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include database configuration
|
// Include database configuration
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Create database connection
|
// Create database connection
|
||||||
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
||||||
|
|
@ -379,7 +379,7 @@ $status_config = [
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// Close database connection
|
// Close database connection
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
// Require login for this page
|
// Require login for this page
|
||||||
require_once(__DIR__ . '/includes/login_required.php');
|
require_once(__DIR__ . '/includes/login_required.php');
|
||||||
|
|
||||||
// Include database configuration
|
// Include billing bootstrap (loads config and DB helper)
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Create database connection
|
// Create database connection
|
||||||
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
||||||
|
|
@ -136,7 +136,7 @@ $result = mysqli_query($db, $query);
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// Close database connection
|
// Close database connection
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -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 login for ordering
|
||||||
require_once(__DIR__ . '/includes/login_required.php');
|
require_once(__DIR__ . '/includes/login_required.php');
|
||||||
|
|
||||||
// Include database configuration
|
// Include billing bootstrap (loads config and DB helper)
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Create database connection
|
// Create database connection
|
||||||
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
||||||
|
|
@ -308,7 +308,7 @@ if ($row['price_monthly'] == 0.0) {
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
// Close database connection
|
// Close database connection
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
<?php include(__DIR__ . '/includes/footer.php'); ?>
|
<?php include(__DIR__ . '/includes/footer.php'); ?>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
session_name("gameservers_website");
|
session_name("gameservers_website");
|
||||||
session_start();
|
session_start();
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Simple registration form (creates a user in {table_prefix}users with MD5 password)
|
// Simple registration form (creates a user in {table_prefix}users with MD5 password)
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['username']) && !empty($_POST['password'])) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['username']) && !empty($_POST['password'])) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ if (session_status() === PHP_SESSION_NONE) {
|
||||||
session_name("gameservers_website");
|
session_name("gameservers_website");
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
require_once(__DIR__ . '/includes/login_required.php');
|
require_once(__DIR__ . '/includes/login_required.php');
|
||||||
require_once(__DIR__ . '/includes/log.php');
|
require_once(__DIR__ . '/includes/log.php');
|
||||||
|
|
||||||
|
|
@ -264,7 +264,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['confirm_renewal'])) {
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// Close database connection
|
// Close database connection
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ session_name("gameservers_website");
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
// Include database configuration
|
// Include database configuration
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Create database connection
|
// Create database connection
|
||||||
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
$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
|
// Close database connection
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php
|
<?php
|
||||||
// Include database configuration
|
// Include billing bootstrap (loads config and DB helper)
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Create database connection
|
// Create database connection
|
||||||
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
||||||
|
|
@ -165,7 +165,7 @@ $result = mysqli_query($db, $query);
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// Close database connection
|
// Close database connection
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ ini_set('display_startup_errors', 1);
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
// Include database configuration
|
// Include database configuration
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Create database connection
|
// Create database connection
|
||||||
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
||||||
|
|
@ -38,7 +38,7 @@ $services = $db->query($qry_services);
|
||||||
|
|
||||||
if (!$services) {
|
if (!$services) {
|
||||||
echo "<meta http-equiv='refresh' content='1'>";
|
echo "<meta http-equiv='refresh' content='1'>";
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,7 +123,7 @@ include(__DIR__ . '/includes/menu.php');
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// Close database connection
|
// Close database connection
|
||||||
mysqli_close($db);
|
billing_maybe_close_db($db);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php include(__DIR__ . '/includes/footer.php'); ?>
|
<?php include(__DIR__ . '/includes/footer.php'); ?>
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
* accessible in production.
|
* accessible in production.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Include database configuration
|
// Include billing bootstrap (loads config and DB helper)
|
||||||
require_once(__DIR__ . '/includes/config.inc.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
|
|
||||||
// Create database connection
|
// Create database connection
|
||||||
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue