Description
Projet complet de gestion hôtelière avec PHP/MySQL et déploiement via Docker Compose. L'application dispose d'un espace public (chambres, réservations, profil) et d'un panneau admin pour gérer chambres, clients et réservations. Architecture MVC-like avec includes, config séparée et requêtes PDO préparées.
Fonctionnalités
Gestion des chambres
Liste, détails, types et prix par nuit
Réservations
Création, suivi en cours/passées, suppression admin
Clients
Inscription, connexion, profil, recherche admin
Planning
Vue calendrier des réservations par chambre
Admin
Interface complète : CRUD chambres, clients, réservations
Docker
Apache + PHP + MySQL conteneurisés, .htaccess, php.ini
Structure du projet
hotel_neptune/
admin/ chambres.php, clients.php, reservations.php
public/ index.php, chambre_info.php, reservation.php, planning.php
config/ db.php (connexion PDO)
includes/ header.php, footer.php, function.php
docker/apache/ apache.conf, .htaccess, entrypoint.sh, php.ini
assets/ css/style.css, js/scripts.js
admin/ chambres.php, clients.php, reservations.php
public/ index.php, chambre_info.php, reservation.php, planning.php
config/ db.php (connexion PDO)
includes/ header.php, footer.php, function.php
docker/apache/ apache.conf, .htaccess, entrypoint.sh, php.ini
assets/ css/style.css, js/scripts.js
Code source
public/index.php
reservation.php
config/db.php
docker/apache.conf
public/index.php — Liste des chambres
<?php
require_once __DIR__ . '/../config/db.php';
require_once __DIR__ . '/../includes/header.php';
$pdo = getPDO();
$stmt = $pdo->query("SELECT id_chambre, numero, type, prix FROM chambre ORDER BY numero");
$chambres = $stmt->fetchAll();
?>
<h2>Bienvenue à l'Hôtel Neptune</h2>
<p>Découvrez nos chambres :</p>
<table>
<thead>
<tr>
<th>Numéro</th>
<th>Type</th>
<th>Prix / nuit</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($chambres as $ch): ?>
<tr>
<td><?= htmlspecialchars($ch['numero']) ?></td>
<td><?= htmlspecialchars($ch['type']) ?></td>
<td><?= htmlspecialchars($ch['prix']) ?> €</td>
<td>
<a href="chambre_info.php?id=<?= $ch['id_chambre'] ?>">Détails</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php require_once __DIR__ . '/../includes/footer.php'; ?>
public/reservation.php — Mes réservations
<?php
require_once __DIR__ . '/../config/db.php';
require_once __DIR__ . '/../includes/header.php';
require_once __DIR__ . '/../includes/functions.php';
if (!isLoggedIn()) {
echo "<p>Vous devez être connecté.</p>";
require_once __DIR__ . '/../includes/footer.php';
exit;
}
$pdo = getPDO();
$id_client = $_SESSION['user']['id'];
$sql = "SELECT r.*, c.numero AS chambre_numero
FROM reservation r
JOIN chambre c ON r.id_chambre = c.id_chambre
WHERE r.id_client = ?
ORDER BY r.date_debut DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute([$id_client]);
$reservations = $stmt->fetchAll();
$today = new DateTime();
?>
<h2>Mes réservations</h2>
<h3>À venir</h3>
<table>
<tr><th>Chambre</th><th>Arrivée</th><th>Départ</th><th>Statut</th></tr>
<?php foreach ($reservations as $r):
if (new DateTime($r['date_fin']) >= $today): ?>
<tr>
<td>Chambre <?= htmlspecialchars($r['chambre_numero']) ?></td>
<td><?= htmlspecialchars($r['date_debut']) ?></td>
<td><?= htmlspecialchars($r['date_fin']) ?></td>
<td><?= htmlspecialchars($r['statut']) ?></td>
</tr>
<?php endif; endforeach; ?>
</table>
<?php require_once __DIR__ . '/../includes/footer.php'; ?>
config/db.php — Connexion PDO
<?php
function getPDO(): PDO {
$host = getenv('DB_HOST') ?: 'db';
$dbname = getenv('DB_NAME') ?: 'hotel_neptune';
$user = getenv('DB_USER') ?: 'root';
$pass = getenv('DB_PASS') ?: 'root';
$dsn = "mysql:host=$host;dbname=$dbname;charset=utf8mb4";
return new PDO($dsn, $user, $pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
}
?>
docker/apache/apache.conf
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
Require all granted
Options -Indexes +FollowSymLinks
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>