Remove db.php and add navigation menu to all pages

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-10-22 01:35:14 +00:00
parent 85555549f9
commit dfe1d0d2db
10 changed files with 190 additions and 98 deletions

View file

@ -1,29 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Server List - GameServers.World</title>
</head>
<body>
<?php <?php
// gameservers.world admin — mysqli only, bulk + per-row update, image base URL + small button // gameservers.world admin — mysqli only, bulk + per-row update, image base URL + small button
global $db;
/* === Configure your site base URL for image previews (MUST end with or without slash; we'll normalize) === */ /* === Configure your site base URL for image previews (MUST end with or without slash; we'll normalize) === */
$SITE_BASE_URL = 'http://gameservers.world/'; $SITE_BASE_URL = 'http://gameservers.world/';
/* include DB (must provide $db as mysqli) */ // Include database configuration
$try = [ require_once(__DIR__ . '/includes/config.inc.php');
__DIR__ . "db.php",
(defined('ABSPATH') ? ABSPATH : $_SERVER['DOCUMENT_ROOT']) . "db.php",
"db.php"
];
foreach ($try as $p) { if (empty($db) && is_readable($p)) include_once $p; }
/* show errors to WP admins during setup */ // Create database connection
if (function_exists('current_user_can') && current_user_can('manage_options')) { @ini_set('display_errors','1'); error_reporting(E_ALL); } $db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$db) {
/* guards & helpers */ die("Connection failed: " . mysqli_connect_error());
if (!($db instanceof mysqli)) {
echo '<div style="border:1px solid #c00;padding:10px;margin:10px 0;">
<b>Admin panel error:</b> <code>$db</code> must be a <code>mysqli</code> connection (check panel/_db.php).
</div>';
return;
} }
// Include menu
include(__DIR__ . '/includes/menu.php');
/* show errors during setup */
@ini_set('display_errors','1');
error_reporting(E_ALL);
function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
function esc_mysqli($db, $v){ return $db->real_escape_string($v); } function esc_mysqli($db, $v){ return $db->real_escape_string($v); }
function fetch_all_assoc($db, $sql){ function fetch_all_assoc($db, $sql){
@ -318,3 +321,9 @@ document.querySelectorAll('.locs-box').forEach(function(box){
}); });
</script> </script>
<?php
// Close database connection
mysqli_close($db);
?>
</body>
</html>

View file

@ -1,17 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart - GameServers.World</title>
</head>
<body>
<?php <?php
ini_set('display_errors', 1); ini_set('display_errors', 1);
ini_set('display_startup_errors', 1); ini_set('display_startup_errors', 1);
error_reporting(E_ALL); error_reporting(E_ALL);
global $db, $view, $settings;
include "db.php"; // Include database configuration
require_once(__DIR__ . '/includes/config.inc.php');
// Create database connection
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}
// Include menu
include(__DIR__ . '/includes/menu.php');
$user_id=$_SESSION['user_id'] ?? 0; $user_id=$_SESSION['user_id'] ?? 0;
$user_id = 186; // For testing purposes, set a default user ID $user_id = 186; // For testing purposes, set a default user ID
if ($user_id <= 0) { if ($user_id <= 0) {
echo "<center><h4>Please login to view your cart</h4></center>"; echo "<center><h4>Please login to view your cart</h4></center>";
mysqli_close($db);
echo "</body></html>";
return; return;
} }
@ -256,3 +274,9 @@ $apiBase = '/paypal/api';
</div> </div>
<?php
// Close database connection
mysqli_close($db);
?>
</body>
</html>

View file

@ -1,39 +0,0 @@
text/x-generic _db.php ( PHP script, ASCII text, with CRLF line terminators )
<?php
// Include the centralized database configuration
require_once(__DIR__ . '/includes/config.inc.php');
// Use the configuration variables from config.inc.php
$servername = $db_host;
$username = $db_user;
$password = $db_pass;
$dbname = $db_name;
// Create connection
$db = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$db) {
echo "failed";
die("Connection failed: " . mysqli_connect_error());
}
//This gets the current users role , Admin, User or other
//returning true/false
//$isAdmin = isAdmin(186);
function isAdmin($userID){
$adminField = $db->query("SELECT 'users_role' FROM ogp_users WHERE userID = $userID");
if($adminField == "admin"){
$adminStatus = true;
}else{
$adminStatus = false;
}
return $adminStatus;
}
function logger($logtext){
file_put_contents("logfile.txt",$logtext . PHP_EOL,FILE_APPEND);
}
?>

View file

@ -0,0 +1,55 @@
<?php
/**
* Navigation Menu for GameServers.World Website
* This file provides a consistent navigation menu across all website pages
*/
// Start the website session to check if user is logged in (if not already started)
if (session_status() === PHP_SESSION_NONE) {
session_name("gameservers_website");
session_start();
}
// Check login status
$is_logged_in = isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id']);
$username = $is_logged_in ? htmlspecialchars($_SESSION['website_username']) : '';
?>
<style>
.gsw-header{display:flex;justify-content:space-between;align-items:center;padding:16px 24px;background:rgba(102, 126, 234, 0.95);backdrop-filter:blur(10px);margin-bottom:20px;box-shadow:0 2px 4px rgba(0,0,0,0.1);}
.gsw-header-left{font-weight:700;font-size:1.2rem;color:#fff;}
.gsw-header-left a{color:#fff;text-decoration:none;}
.gsw-header-nav{display:flex;gap:20px;align-items:center;}
.gsw-nav-link{color:#fff;text-decoration:none;font-size:0.95rem;transition:opacity 0.2s;}
.gsw-nav-link:hover{opacity:0.8;text-decoration:underline;}
.gsw-header-right{display:flex;gap:12px;align-items:center;}
.gsw-user-info{color:#fff;font-size:0.95rem;}
.gsw-header-btn{padding:8px 16px;background:#fff;color:#667eea;border-radius:6px;text-decoration:none;font-weight:600;transition:transform 0.2s;}
.gsw-header-btn:hover{transform:translateY(-2px);}
@media(max-width:768px){
.gsw-header{flex-direction:column;gap:12px;}
.gsw-header-nav{flex-wrap:wrap;justify-content:center;}
}
</style>
<div class="gsw-header">
<div class="gsw-header-left">
<a href="/">GameServers.World</a>
</div>
<nav class="gsw-header-nav">
<a href="/" class="gsw-nav-link">Home</a>
<a href="/serverlist.php" class="gsw-nav-link">Game Servers</a>
<a href="/cart.php" class="gsw-nav-link">Cart</a>
<?php if ($is_logged_in): ?>
<a href="/adminserverlist.php" class="gsw-nav-link">Admin</a>
<?php endif; ?>
<a href="http://panel.iaregamer.com" class="gsw-nav-link" target="_blank">Panel Login</a>
</nav>
<div class="gsw-header-right">
<?php if ($is_logged_in): ?>
<span class="gsw-user-info">Welcome, <?php echo $username; ?>!</span>
<a href="/logout.php" class="gsw-header-btn">Logout</a>
<?php else: ?>
<a href="/login.php" class="gsw-header-btn">Login</a>
<?php endif; ?>
</div>
</div>

View file

@ -1,12 +1,3 @@
<?php
// Start the website session to check if user is logged in
session_name("gameservers_website");
session_start();
// Check login status
$is_logged_in = isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id']);
$username = $is_logged_in ? htmlspecialchars($_SESSION['website_username']) : '';
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -40,28 +31,11 @@ $username = $is_logged_in ? htmlspecialchars($_SESSION['website_username']) : ''
.gsw-btn{border:1px solid;border-radius:8px;padding:10px 14px;text-decoration:none;display:inline-block;font-weight:600} .gsw-btn{border:1px solid;border-radius:8px;padding:10px 14px;text-decoration:none;display:inline-block;font-weight:600}
.gsw-fine{font-size:.92rem;opacity:.9;text-align:center;margin-top:10px} .gsw-fine{font-size:.92rem;opacity:.9;text-align:center;margin-top:10px}
.gsw-header{display:flex;justify-content:space-between;align-items:center;padding:16px 24px;background:rgba(255,255,255,0.1);backdrop-filter:blur(10px);margin-bottom:20px}
.gsw-header-left{font-weight:700;font-size:1.2rem;color:#fff}
.gsw-header-right{display:flex;gap:12px;align-items:center}
.gsw-user-info{color:#fff;font-size:0.95rem}
.gsw-header-btn{padding:8px 16px;background:#fff;color:#667eea;border-radius:6px;text-decoration:none;font-weight:600;transition:transform 0.2s}
.gsw-header-btn:hover{transform:translateY(-2px)}
</style> </style>
</head> </head>
<body> <body>
<div class="gsw-header"> <?php include(__DIR__ . '/includes/menu.php'); ?>
<div class="gsw-header-left">GameServers.World</div>
<div class="gsw-header-right">
<?php if ($is_logged_in): ?>
<span class="gsw-user-info">Welcome, <?php echo $username; ?>!</span>
<a href="logout.php" class="gsw-header-btn">Logout</a>
<?php else: ?>
<a href="login.php" class="gsw-header-btn">Login</a>
<?php endif; ?>
</div>
</div>
<div class="gsw-outer-full"> <div class="gsw-outer-full">
<div class="gsw-page-center"> <div class="gsw-page-center">

View file

@ -3,8 +3,19 @@
session_name("gameservers_website"); session_name("gameservers_website");
session_start(); session_start();
// Include database connection // Include database configuration
require_once('db.php'); require_once(__DIR__ . '/includes/config.inc.php');
// Create database connection
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}
// Logger function
function logger($logtext){
file_put_contents(__DIR__ . "/logfile.txt", $logtext . PHP_EOL, FILE_APPEND);
}
// Check if user is already logged in // Check if user is already logged in
if (isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id'])) { if (isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id'])) {
@ -61,6 +72,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) {
} }
} }
} }
// Close database connection
mysqli_close($db);
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
@ -68,7 +82,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) {
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - GameServers.World</title> <title>Login - GameServers.World</title>
<style> <style>
* { * {
margin: 0; margin: 0;
padding: 0; padding: 0;
@ -201,6 +215,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) {
</style> </style>
</head> </head>
<body> <body>
<?php include(__DIR__ . '/includes/menu.php'); ?>
<div class="login-container"> <div class="login-container">
<div class="login-header"> <div class="login-header">
<h1>Welcome Back</h1> <h1>Welcome Back</h1>

View file

@ -3,8 +3,10 @@
session_name("gameservers_website"); session_name("gameservers_website");
session_start(); session_start();
// Include database connection for logging // Logger function
require_once('db.php'); function logger($logtext){
file_put_contents(__DIR__ . "/logfile.txt", $logtext . PHP_EOL, FILE_APPEND);
}
// Log the logout // Log the logout
if (isset($_SESSION['website_username'])) { if (isset($_SESSION['website_username'])) {

View file

@ -1,3 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Order Server - GameServers.World</title>
</head>
<body>
<?php <?php
/* /*
@ -11,7 +19,18 @@ In our website, we are setting "post" pages with a "Tag". The first tag in our p
There are other methods that might be better to get the info. But all we need is the "service_ID" in the "ogp_billing_services" table There are other methods that might be better to get the info. But all we need is the "service_ID" in the "ogp_billing_services" table
This method means we can use one code block in every game page and fill in the data dynamically. This method means we can use one code block in every game page and fill in the data dynamically.
*/ */
include "db.php";
// Include database configuration
require_once(__DIR__ . '/includes/config.inc.php');
// Create database connection
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}
// Include menu
include(__DIR__ . '/includes/menu.php');
if (isset($_POST['save']) AND !empty($_POST['description'])) if (isset($_POST['save']) AND !empty($_POST['description']))
@ -287,3 +306,9 @@ if ($row['price_monthly'] == 0.0) {
} }
?> ?>
</div> </div>
<?php
// Close database connection
mysqli_close($db);
?>
</body>
</html>

View file

@ -1,11 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Server List - GameServers.World</title>
</head>
<body>
<?php <?php
ini_set('display_errors', 1); ini_set('display_errors', 1);
ini_set('display_startup_errors', 1); ini_set('display_startup_errors', 1);
error_reporting(E_ALL); error_reporting(E_ALL);
include "db.php"; // Include database configuration
require_once(__DIR__ . '/includes/config.inc.php');
// Create database connection
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}
// Save new description if admin // Save new description if admin
if (isset($_POST['save']) && !empty($_POST['description'])) { if (isset($_POST['save']) && !empty($_POST['description'])) {
@ -25,8 +38,12 @@ $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);
return; return;
} }
// Include menu
include(__DIR__ . '/includes/menu.php');
?> ?>
<div style="border-left:10px solid transparent;"> <div style="border-left:10px solid transparent;">
@ -95,5 +112,9 @@ if (!$services) {
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<?php
// Close database connection
mysqli_close($db);
?>
</body>
</html>

View file

@ -10,8 +10,14 @@
* accessible in production. * accessible in production.
*/ */
// Include database connection // Include database configuration
require_once('db.php'); require_once(__DIR__ . '/includes/config.inc.php');
// Create database connection
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}
echo "<!DOCTYPE html> echo "<!DOCTYPE html>
<html> <html>