🔐 ЗАЩИТА:
- ip_check.php — фильтр по IP
- session_start() + проверка $_SESSION['user']
- htmlspecialchars() — защита от XSS
- PDO — подготовленные запросы
- POST-форма удаления — защита от GET-запросов
🔌 ПОДКЛЮЧЕНИЯ:
- ../includes/db.php — подключение к БД
- ../includes/header.php — шапка сайта
- ../includes/admin_menu.php — меню админки
- ../includes/footer.php — подвал
🗂️ ТАБЛИЦЫ БД:
- articles + categories (LEFT JOIN)
- code_posts + categories (LEFT JOIN)
- ORDER BY created_at DESC — сортировка по дате
⚙️ ФУНКЦИИ:
- Статьи — список + add/edit/delete
- Код-посты — список + add/edit/delete
- Управление категориями
- Загрузка файлов (upload.php)
- Сообщения из формы (feedback.php)
✅ Админка безопасна, но пока не выложена — эксклюзив :)
<?php
include('ip_check.php');
session_start();
if (!isset($_SESSION['user'])) {
header("Location: login.php");
exit;
}
// Подключаем БД
require '../includes/db.php';
include '../includes/header.php';
?>
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/css/adminka.css">
</head>
<body>
<div class="container">
<?php include '../includes/admin_menu.php'; ?>
<li><a href="feedback.php">Сообщения с формы</a></li>
<li><a href="upload.php">Загрузка файлов</a></li>
<p><a href="categories.php">→ Управление категориями</a></p>
<h2>Статьи</h2>
<p><a href="add.php">+ Добавить статью</a></p>
<table border="1" cellpadding="10">
<tr>
<th>ID</th>
<th>Заголовок</th>
<th>Категория</th>
<th>Дата</th>
<th>Действия</th>
</tr>
<?php
$stmt = $pdo->query("SELECT a.id, a.title, a.created_at, c.name as category
FROM articles a LEFT JOIN categories c ON a.category_id = c.id
ORDER BY a.created_at DESC");
while ($row = $stmt->fetch()):
?>
<tr>
<td><?= $row['id'] ?></td>
<td><?= htmlspecialchars($row['title']) ?></td>
<td><?= $row['category'] ?: '—' ?></td>
<td><?= $row['created_at'] ?></td>
<td>
<a href="edit.php?id=<?= $row['id'] ?>">Редактировать</a> |
<form method="POST" action="delete.php" style="display:inline;">
<input type="hidden" name="id" value="<?= $row['id'] ?>">
<button type="submit" onclick="return confirm('Удалить?')" style="background:none; border:none; color:#ff4444; cursor:pointer; text-decoration:underline;">
Удалить
</button>
</form>
</td>
</tr>
<?php endwhile; ?>
</table>
<h2>Код-посты</h2>
<p><a href="add_code_post.php">+ Добавить код-пост</a></p>
<table border="1" cellpadding="10">
<tr>
<th>ID</th>
<th>Заголовок</th>
<th>Категория</th>
<th>Дата</th>
<th>Действия</th>
</tr>
<?php
$stmt = $pdo->query("SELECT p.id, p.title, p.created_at, c.name as category
FROM code_posts p
LEFT JOIN categories c ON p.category_id = c.id
ORDER BY p.created_at DESC");
while ($row = $stmt->fetch()):
?>
<tr>
<td><?= $row['id'] ?></td>
<td><?= htmlspecialchars($row['title']) ?></td>
<td><?= $row['category'] ?: '—' ?></td>
<td><?= $row['created_at'] ?></td>
<td>
<a href="edit_code_post.php?id=<?= $row['id'] ?>">Редактировать</a> |
<form method="POST" action="delete_code_post.php" style="display:inline;">
<input type="hidden" name="id" value="<?= $row['id'] ?>">
<button type="submit" onclick="return confirm('Удалить?')" style="background:none; border:none; color:#ff4444; cursor:pointer; text-decoration:underline;">
Удалить
</button>
</form>
</td>
</tr>
<?php endwhile; ?>
</table>
<br/><br/>
<?php include '../includes/links.php';?>
</div>
<?php include '../includes/footer.php';?>
</body>
</html>
Комментарии
Пока нет комментариев. Будьте первым!