Загрузка данных
<?php
session_start();
// Обработка формы авторизации
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
// Здесь должна быть проверка данных в БД
// Упрощённый пример проверки
if ($username === 'admin' && $password === 'admin123') {
$_SESSION['user'] = $username;
$_SESSION['is_admin'] = true;
header('Location: admin_panel.php');
exit;
} elseif ($username === 'user' && $password === 'user123') {
$_SESSION['user'] = $username;
$_SESSION['is_admin'] = false;
header('Location: index.php');
exit;
} else {
$error = 'Неверные логин или пароль';
}
}
// Обработка формы регистрации
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['register'])) {
$reg_username = $_POST['reg_username'];
$reg_password = $_POST['reg_password'];
$reg_email = $_POST['reg_email'];
// Здесь должна быть запись в БД
$success = 'Регистрация успешна! Теперь вы можете войти.';
}
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Вход и регистрация</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
width: 400px;
}
h2 {
text-align: center;
color: #333;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
color: #555;
}
input[type="text"],
input[type="password"],
input[type="email"] {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
button {
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
.tabs {
display: flex;
margin-bottom: 20px;
}
.tab {
flex: 1;
text-align: center;
padding: 10px;
cursor: pointer;
background-color: #e9ecef;
border: 1px solid #ddd;
}
.tab.active {
background-color: white;
border-bottom: 1px solid white;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.error {
color: red;
text-align: center;
margin-top: 10px;
}
.success {
color: green;
text-align: center;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2>Вход и регистрация</h2>
<?php if (isset($error)): ?>
<div class="error"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<?php if (isset($success)): ?>
<div class="success"><?= htmlspecialchars($success) ?></div>
<?php endif; ?>
<div class="tabs">
<div class="tab active" onclick="showTab('login')">Вход</div>
<div class="tab" onclick="showTab('register')">Регистрация</div>
<div class="tab" onclick="showTab('admin')">Админ-панель</div>
</div>
<!-- Форма входа -->
<div id="login" class="tab-content active">
<form method="POST">
<div class="form-group">
<label for="username">Логин:</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<label for="password">Пароль:</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit" name="login">Войти</button>
</form>
</div>
<!-- Форма регистрации -->
<div id="register" class="tab-content">
<form method="POST">
<div class="form-group">
<label for="reg_username">Логин:</label>
<input type="text" id="reg_username" name="reg_username" required>
</div>
<div class="form-group">
<label for="reg_email">Email:</label>
<input type="email" id="reg_email" name="reg_email" required>
</div>
<div class="form-group">
<label for="reg_password">Пароль:</label>
<input type="password" id="reg_password" name="reg_password" required>
</div>
<button type="submit" name="register">Зарегистрироваться</button>
</form>
</div>
<!-- Вход в админ-панель -->
<div id="admin" class="tab-content">
<p>Для входа в админ-панель используйте:</p>
<ul>
<li><strong>Логин:</strong> admin</li>
<li><strong>Пароль:</strong> admin123</li>
</ul>
<form method="POST">
<div class="form-group">
<label for="admin_username">Логин:</label>
<input type="text" id="admin_username" name="username" required>
</div>
<div class="form-group">
<label for="admin_password">Пароль:</label>
<input type="password" id="admin_password" name="password" required>
</div>
<button type="submit" name="login">Войти в админ-панель</button>
</form>
</div>
</div>
<script>
function showTab(tabName) {
// Скрыть все вкладки
document.querySelectorAll('.tab-content').forEach(tab => {
tab.classList.remove('active');
});
document.querySelectorAll('.tab').forEach(tab => {
tab.classList.remove('active');
});
// Показать выбранную вкладку
document.getElementById(tabName).classList.add('active');
event.target.classList.add('active');
}
</script>
</body>
</html>