Add website login, logout pages and update index with session management
Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
parent
a0790f58eb
commit
a7bb9d5b31
3 changed files with 305 additions and 3 deletions
|
|
@ -1,5 +1,18 @@
|
|||
<?php
|
||||
echo <<<'HTML'
|
||||
// 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>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>GameServers.World - Virtual Private Gameservers</title>
|
||||
<style>
|
||||
.gsw-outer-full{box-sizing:border-box;width:100vw!important;margin-left:calc(50% - 50vw)!important;margin-right:calc(50% - 50vw)!important}
|
||||
.gsw-page-center{display:flex;justify-content:center;padding:24px 12px}
|
||||
|
|
@ -27,7 +40,28 @@ echo <<<'HTML'
|
|||
.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-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>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="gsw-header">
|
||||
<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-page-center">
|
||||
|
|
@ -77,6 +111,6 @@ echo <<<'HTML'
|
|||
</section>
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
240
_website/login.php
Normal file
240
_website/login.php
Normal file
|
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
// Start a separate session for the website (not the panel session)
|
||||
session_name("gameservers_website");
|
||||
session_start();
|
||||
|
||||
// Include database connection
|
||||
require_once('db.php');
|
||||
|
||||
// Check if user is already logged in
|
||||
if (isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id'])) {
|
||||
// Already logged in, redirect to appropriate page
|
||||
header('Location: /');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Initialize error message
|
||||
$error_message = '';
|
||||
$success_message = '';
|
||||
|
||||
// Process login form submission
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) {
|
||||
$username = trim($_POST['ulogin'] ?? '');
|
||||
$password = $_POST['upassword'] ?? '';
|
||||
|
||||
if (empty($username) || empty($password)) {
|
||||
$error_message = 'Please enter both username and password.';
|
||||
} else {
|
||||
// Sanitize username to prevent SQL injection
|
||||
$username = mysqli_real_escape_string($db, $username);
|
||||
|
||||
// Query the panel database for the user
|
||||
$query = "SELECT user_id, users_login, users_passwd, users_role, users_email FROM ogp_users WHERE users_login = '$username'";
|
||||
$result = mysqli_query($db, $query);
|
||||
|
||||
if ($result && mysqli_num_rows($result) === 1) {
|
||||
$user = mysqli_fetch_assoc($result);
|
||||
|
||||
// Verify password (panel uses MD5)
|
||||
if (md5($password) === $user['users_passwd']) {
|
||||
// Login successful - create website session
|
||||
$_SESSION['website_user_id'] = $user['user_id'];
|
||||
$_SESSION['website_username'] = $user['users_login'];
|
||||
$_SESSION['website_user_role'] = $user['users_role'];
|
||||
$_SESSION['website_user_email'] = $user['users_email'];
|
||||
$_SESSION['website_login_time'] = time();
|
||||
|
||||
$success_message = 'Login successful! Redirecting...';
|
||||
|
||||
// Log the login
|
||||
logger("Website login successful: " . $user['users_login']);
|
||||
|
||||
// Redirect after 2 seconds
|
||||
header('Refresh: 2; URL=/');
|
||||
} else {
|
||||
$error_message = 'Invalid username or password.';
|
||||
logger("Website login failed - wrong password: $username");
|
||||
}
|
||||
} else {
|
||||
$error_message = 'Invalid username or password.';
|
||||
logger("Website login failed - user not found: $username");
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - GameServers.World</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 1.8rem;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
color: #666;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border: 2px solid #e1e8ed;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.btn-login {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.btn-login:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.btn-login:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
background-color: #fee;
|
||||
border: 1px solid #fcc;
|
||||
color: #c33;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background-color: #efe;
|
||||
border: 1px solid #cfc;
|
||||
color: #3c3;
|
||||
}
|
||||
|
||||
.footer-links {
|
||||
margin-top: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.footer-links a {
|
||||
color: #667eea;
|
||||
text-decoration: none;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.footer-links a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.divider {
|
||||
margin: 20px 0;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<div class="login-header">
|
||||
<h1>Welcome Back</h1>
|
||||
<p>Sign in to your GameServers account</p>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($error_message)): ?>
|
||||
<div class="alert alert-error"><?php echo htmlspecialchars($error_message); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($success_message)): ?>
|
||||
<div class="alert alert-success"><?php echo htmlspecialchars($success_message); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST" action="login.php">
|
||||
<div class="form-group">
|
||||
<label for="ulogin">Username</label>
|
||||
<input type="text" id="ulogin" name="ulogin" required autofocus>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="upassword">Password</label>
|
||||
<input type="password" id="upassword" name="upassword" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" name="login" class="btn-login">Sign In</button>
|
||||
</form>
|
||||
|
||||
<div class="divider">or</div>
|
||||
|
||||
<div class="footer-links">
|
||||
<a href="/">Back to Home</a> |
|
||||
<a href="../index.php">Panel Login</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
28
_website/logout.php
Normal file
28
_website/logout.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
// Start the website session
|
||||
session_name("gameservers_website");
|
||||
session_start();
|
||||
|
||||
// Include database connection for logging
|
||||
require_once('db.php');
|
||||
|
||||
// Log the logout
|
||||
if (isset($_SESSION['website_username'])) {
|
||||
logger("Website logout: " . $_SESSION['website_username']);
|
||||
}
|
||||
|
||||
// Destroy all session data
|
||||
$_SESSION = array();
|
||||
|
||||
// Destroy the session cookie
|
||||
if (isset($_COOKIE[session_name()])) {
|
||||
setcookie(session_name(), '', time() - 42000, '/');
|
||||
}
|
||||
|
||||
// Destroy the session
|
||||
session_destroy();
|
||||
|
||||
// Redirect to home page
|
||||
header('Location: /');
|
||||
exit();
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue