From 74ebab4b24f7930c0adb25f70ef3a36cbf8ce342 Mon Sep 17 00:00:00 2001 From: "JARNOUEN DE VILLARTAY Ulysse (SAFRAN AIRCRAFT ENGINES)" Date: Wed, 15 Apr 2026 16:03:11 +0200 Subject: [PATCH 1/5] tp4 ex1 --- R3.01/tp/tp4/ex1/index.php | 29 +++++++++-- R3.01/tp/tp4/ex1/views/main.php | 86 ++++++++++++++++++--------------- 2 files changed, 71 insertions(+), 44 deletions(-) diff --git a/R3.01/tp/tp4/ex1/index.php b/R3.01/tp/tp4/ex1/index.php index b1873cc..ceb9fb3 100644 --- a/R3.01/tp/tp4/ex1/index.php +++ b/R3.01/tp/tp4/ex1/index.php @@ -1,6 +1,27 @@ 'Linux', + 'windows' => 'Windows', + 'apple' => 'MacOS', +]; -include './views/main.php'; -?> +$cookieName = 'preferred_os'; +$os = 'linux'; + +// Si le formulaire est soumis, on valide la valeur reçue avant +// de l'enregistrer dans un cookie valable 60 secondes. +if (isset($_POST['os']) && array_key_exists($_POST['os'], $osSet)) { + $os = $_POST['os']; + setcookie($cookieName, $os, time() + 60); + + // On met aussi $_COOKIE à jour pour refléter immédiatement le choix + // sans attendre le rechargement suivant du navigateur. + $_COOKIE[$cookieName] = $os; +} elseif (isset($_COOKIE[$cookieName]) && array_key_exists($_COOKIE[$cookieName], $osSet)) { + // En l'absence de soumission, on relit la préférence mémorisée. + $os = $_COOKIE[$cookieName]; +} + +include_once './views/main.php'; diff --git a/R3.01/tp/tp4/ex1/views/main.php b/R3.01/tp/tp4/ex1/views/main.php index 2aedb2d..1cbff0c 100644 --- a/R3.01/tp/tp4/ex1/views/main.php +++ b/R3.01/tp/tp4/ex1/views/main.php @@ -1,44 +1,50 @@ - - - - - + + + + Cookie OS préféré + + + + +
+
+
+ Changez votre os + $label) { ?> + + +
- - -
- -
- Changez votre os - - - -
- - - -
-
Votre os
- ";?> -
- Rafraîchir la page -
-
- -
- + + +
+
Votre os
+

+ + +

+

+
+ Rafraîchir la page + + + +
+
+
+ -- 2.54.0 From 553b30bdcc3781350b1a5b7a387cbfea37ff9753 Mon Sep 17 00:00:00 2001 From: "JARNOUEN DE VILLARTAY Ulysse (SAFRAN AIRCRAFT ENGINES)" Date: Wed, 15 Apr 2026 16:06:48 +0200 Subject: [PATCH 2/5] tp4 ex2 --- R3.01/tp/tp4/ex2/helpers.php | 81 +++++++++++++++++++--------- R3.01/tp/tp4/ex2/index.php | 71 +++++++++++++++++++++--- R3.01/tp/tp4/ex2/views/tictactoe.php | 32 +++++++---- 3 files changed, 142 insertions(+), 42 deletions(-) diff --git a/R3.01/tp/tp4/ex2/helpers.php b/R3.01/tp/tp4/ex2/helpers.php index 211e12c..f733f64 100644 --- a/R3.01/tp/tp4/ex2/helpers.php +++ b/R3.01/tp/tp4/ex2/helpers.php @@ -1,54 +1,83 @@ '; - for ($i = 0; $i < 3; $i ++){ - echo ""; - for ($j = 0; $j < 3; $j ++){ + for ($i = 0; $i < 3; $i++) { + echo ''; + for ($j = 0; $j < 3; $j++) { + echo ''; - echo ""; - - $pos = 3*$i + $j; - if ($grid[$pos] == 0) + $pos = 3 * $i + $j; + if ($grid[$pos] == 0 && $isInteractive) { echo ""; - if ($grid[$pos] == 1) + } + if ($grid[$pos] == 1) { echo ''; - if ($grid[$pos] == 2) + } + if ($grid[$pos] == 2) { echo ''; + } - echo ""; + echo ''; } - echo ""; + echo ''; } - echo ""; + echo ''; } diff --git a/R3.01/tp/tp4/ex2/index.php b/R3.01/tp/tp4/ex2/index.php index 2c1717b..6222985 100644 --- a/R3.01/tp/tp4/ex2/index.php +++ b/R3.01/tp/tp4/ex2/index.php @@ -1,11 +1,70 @@ array('min_range' => 0, 'max_range' => 8)) + ); + + if ($pos === false || $pos === null) { + $message = 'Coup invalide.'; + } elseif ($grid[$pos] !== 0) { + $message = 'Cette case est déjà occupée.'; + } else { + // On enregistre le coup du joueur courant dans la grille. + $grid[$pos] = $playerTurn; + + if (isWinner($grid, $playerTurn)) { + $message = "Le joueur $playerTurn gagne la partie."; + } elseif (noWinner($grid)) { + $message = 'Match nul.'; + } else { + $playerTurn = nextPlayer($playerTurn); + } + + $_SESSION['grid'] = $grid; + $_SESSION['playerTurn'] = $playerTurn; + } + + $winner = getWinner($grid); + $isGameOver = $winner !== 0 || noWinner($grid); +} + +// Si la page est simplement rafraîchie, on recalcule un message cohérent +// à partir de l'état stocké en session. +if ($message === '') { + if ($winner !== 0) { + $message = "Le joueur $winner gagne la partie."; + } elseif (noWinner($grid)) { + $message = 'Match nul.'; + } +} + +include_once './views/tictactoe.php'; diff --git a/R3.01/tp/tp4/ex2/views/tictactoe.php b/R3.01/tp/tp4/ex2/views/tictactoe.php index 130bf00..8b16508 100644 --- a/R3.01/tp/tp4/ex2/views/tictactoe.php +++ b/R3.01/tp/tp4/ex2/views/tictactoe.php @@ -1,23 +1,35 @@ - + + + Tic Tac Toe + rel="stylesheet" + href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" + /> -
-

Tic Tac Toe :

+

+ + Partie terminée + + Tic Tac Toe : joueur à vous de jouer + +

$message new game"; - ?> + if ($message != '') { + echo '
' . htmlspecialchars($message, ENT_QUOTES) . " nouvelle partie
"; + } else { + echo "

Recommencer la partie

"; + } + ?>
-- 2.54.0 From 17a16feb2db75899513a5ad3a8e6903ec99b8e80 Mon Sep 17 00:00:00 2001 From: "JARNOUEN DE VILLARTAY Ulysse (SAFRAN AIRCRAFT ENGINES)" Date: Wed, 15 Apr 2026 16:20:11 +0200 Subject: [PATCH 3/5] ex3 --- .env.example | 4 + .gitignore | 1 + R3.01/tp/tp3/cinema/sql/cinema.sql | 8 ++ R3.01/tp/tp3/cinema/src/authentification.php | 46 +++++++++ R3.01/tp/tp3/cinema/src/deconnexion.php | 14 +++ R3.01/tp/tp3/cinema/src/films.php | 12 +-- R3.01/tp/tp3/cinema/src/inscription.php | 98 +++++++++++++++++++ R3.01/tp/tp3/cinema/src/modeles/connexion.php | 33 +++++++ .../tp/tp3/cinema/src/modeles/modeleFilms.php | 34 ++++--- .../cinema/src/modeles/modeleUtilisateurs.php | 53 ++++++++++ R3.01/tp/tp3/cinema/src/securite.php | 11 +++ R3.01/tp/tp3/cinema/src/verification.php | 35 +++++++ R3.01/tp/tp3/cinema/src/vues/header.php | 32 +++--- 13 files changed, 353 insertions(+), 28 deletions(-) create mode 100644 .env.example create mode 100644 R3.01/tp/tp3/cinema/src/authentification.php create mode 100644 R3.01/tp/tp3/cinema/src/deconnexion.php create mode 100644 R3.01/tp/tp3/cinema/src/inscription.php create mode 100644 R3.01/tp/tp3/cinema/src/modeles/connexion.php create mode 100644 R3.01/tp/tp3/cinema/src/modeles/modeleUtilisateurs.php create mode 100644 R3.01/tp/tp3/cinema/src/securite.php create mode 100644 R3.01/tp/tp3/cinema/src/verification.php diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..cd5bda4 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +CINEMA_DB_HOST=dwarves.iut-fbleau.fr +CINEMA_DB_USER=foo +CINEMA_DB_PASSWORD=foo +CINEMA_DB_NAME=foo \ No newline at end of file diff --git a/.gitignore b/.gitignore index c60b300..cc0e85f 100644 --- a/.gitignore +++ b/.gitignore @@ -328,3 +328,4 @@ TSWLatexianTemp* # Uncomment the next line to have this generated file ignored. #*Notes.bib +.env \ No newline at end of file diff --git a/R3.01/tp/tp3/cinema/sql/cinema.sql b/R3.01/tp/tp3/cinema/sql/cinema.sql index d53b5aa..e54eef6 100644 --- a/R3.01/tp/tp3/cinema/sql/cinema.sql +++ b/R3.01/tp/tp3/cinema/sql/cinema.sql @@ -19,6 +19,14 @@ SET time_zone = "+00:00"; -- -------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `user` ( + login VARCHAR(50) NOT NULL, + email VARCHAR(255) NOT NULL, + password VARCHAR(255) NOT NULL, + PRIMARY KEY (login) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + -- -- Table structure for table `Artiste` -- diff --git a/R3.01/tp/tp3/cinema/src/authentification.php b/R3.01/tp/tp3/cinema/src/authentification.php new file mode 100644 index 0000000..60fc8b7 --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/authentification.php @@ -0,0 +1,46 @@ + + + + + + Authentification + + + +
+

Authentification

+ + +
Inscription réussie. Vous pouvez maintenant vous connecter.
+ + + +
Vous avez été déconnecté.
+ + + +
Login ou mot de passe incorrect.
+ + +
+ + + + + + + +
+ +

Créer un compte

+
+ + \ No newline at end of file diff --git a/R3.01/tp/tp3/cinema/src/deconnexion.php b/R3.01/tp/tp3/cinema/src/deconnexion.php new file mode 100644 index 0000000..5b74acc --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/deconnexion.php @@ -0,0 +1,14 @@ + +include_once './vues/header.php'; +include_once './vues/vueFilms.php'; +include_once './vues/footer.php'; diff --git a/R3.01/tp/tp3/cinema/src/inscription.php b/R3.01/tp/tp3/cinema/src/inscription.php new file mode 100644 index 0000000..aa0117c --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/inscription.php @@ -0,0 +1,98 @@ + '', + 'email' => '', +); + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $values['login'] = isset($_POST['login']) ? trim($_POST['login']) : ''; + $values['email'] = isset($_POST['email']) ? trim($_POST['email']) : ''; + $password = isset($_POST['password']) ? $_POST['password'] : ''; + + // On valide champ par champ pour pouvoir réafficher proprement le formulaire. + if ($values['login'] === '') { + $errors['login'] = 'Le login est obligatoire.'; + } elseif (!preg_match('/^[a-zA-Z0-9_-]{3,30}$/', $values['login'])) { + $errors['login'] = 'Le login doit contenir entre 3 et 30 caractères alphanumériques, _ ou -.'; + } + + if ($values['email'] === '') { + $errors['email'] = 'L\'email est obligatoire.'; + } elseif (!filter_var($values['email'], FILTER_VALIDATE_EMAIL)) { + $errors['email'] = 'Le format de l\'email est invalide.'; + } + + if ($password === '') { + $errors['password'] = 'Le mot de passe est obligatoire.'; + } elseif (strlen($password) < 8) { + $errors['password'] = 'Le mot de passe doit contenir au moins 8 caractères.'; + } + + if ($values['login'] !== '' && findUserByLogin($values['login']) !== null) { + $errors['login'] = 'Ce login est déjà utilisé.'; + } + + if (empty($errors)) { + $passwordHash = password_hash($password, PASSWORD_DEFAULT); + createUser($values['login'], $values['email'], $passwordHash); + + header('Location: ./authentification.php?registered=1'); + exit; + } +} +?> + + + + + Inscription + + + +
+

Inscription

+

Créez un compte avant d'accéder aux pages du site.

+ +
+ + + + + + + + + + + + + + + + + + + +
+ +

Déjà inscrit ? Se connecter

+
+ + \ No newline at end of file diff --git a/R3.01/tp/tp3/cinema/src/modeles/connexion.php b/R3.01/tp/tp3/cinema/src/modeles/connexion.php new file mode 100644 index 0000000..d8a7378 --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/modeles/connexion.php @@ -0,0 +1,33 @@ + diff --git a/R3.01/tp/tp3/cinema/src/modeles/modeleUtilisateurs.php b/R3.01/tp/tp3/cinema/src/modeles/modeleUtilisateurs.php new file mode 100644 index 0000000..9436318 --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/modeles/modeleUtilisateurs.php @@ -0,0 +1,53 @@ + $dbLogin, + 'email' => $dbEmail, + 'password' => $dbPassword, + ); + } + + mysqli_stmt_close($stmt); + + return $user; +} + +function createUser($login, $email, $passwordHash) +{ + $conn = getConnection(); + $stmt = mysqli_prepare($conn, 'INSERT INTO `user` (login, email, password) VALUES (?, ?, ?)'); + if ($stmt === false) { + die('Préparation SQL impossible : ' . mysqli_error($conn)); + } + + mysqli_stmt_bind_param($stmt, 'sss', $login, $email, $passwordHash); + $success = mysqli_stmt_execute($stmt); + $errorCode = mysqli_errno($conn); + mysqli_stmt_close($stmt); + + // 1062 = violation de clé unique (login déjà pris). + if (!$success && $errorCode === 1062) { + return false; + } + + if (!$success) { + die('Insertion SQL impossible : ' . mysqli_error($conn)); + } + + return true; +} diff --git a/R3.01/tp/tp3/cinema/src/securite.php b/R3.01/tp/tp3/cinema/src/securite.php new file mode 100644 index 0000000..89125e3 --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/securite.php @@ -0,0 +1,11 @@ + - - - Films - + + + Films + - - - -
+ + + +
+ -- 2.54.0 From 0da6bcf803cc84aa1e8f1a253412547ea12eb2a0 Mon Sep 17 00:00:00 2001 From: "JARNOUEN DE VILLARTAY Ulysse (SAFRAN AIRCRAFT ENGINES)" Date: Wed, 15 Apr 2026 16:54:08 +0200 Subject: [PATCH 4/5] refactor connexion --- R3.01/tp/tp3/cinema/src/modeles/connexion.php | 9 ++++----- .../tp/tp3/cinema/src/modeles/modeleFilms.php | 19 ------------------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/R3.01/tp/tp3/cinema/src/modeles/connexion.php b/R3.01/tp/tp3/cinema/src/modeles/connexion.php index d8a7378..53123d1 100644 --- a/R3.01/tp/tp3/cinema/src/modeles/connexion.php +++ b/R3.01/tp/tp3/cinema/src/modeles/connexion.php @@ -10,10 +10,10 @@ function getConnection() // On autorise deux modes de configuration : // 1) via des variables d'environnement ; // 2) en remplaçant directement les valeurs par votre login/mot de passe. - $host = getenv('CINEMA_DB_HOST') ? getenv('CINEMA_DB_HOST') : 'localhost'; - $user = getenv('CINEMA_DB_USER') ? getenv('CINEMA_DB_USER') : ''; - $password = getenv('CINEMA_DB_PASSWORD') ? getenv('CINEMA_DB_PASSWORD') : ''; - $database = getenv('CINEMA_DB_NAME') ? getenv('CINEMA_DB_NAME') : ''; + $host = getenv('DB_HOST'); + $user = getenv('DB_USER'); + $password = getenv('DB_PASSWORD'); + $database = getenv('DB_NAME'); if ($user === '' || $database === '') { die( @@ -21,7 +21,6 @@ function getConnection() "ou via les variables d'environnement CINEMA_DB_HOST, CINEMA_DB_USER, CINEMA_DB_PASSWORD et CINEMA_DB_NAME." ); } - var_dump($host, $user, $password, $database); $conn = mysqli_connect($host, $user, $password, $database, 3306); if ($conn === false) { die('Connexion MySQL impossible : ' . mysqli_connect_error()); diff --git a/R3.01/tp/tp3/cinema/src/modeles/modeleFilms.php b/R3.01/tp/tp3/cinema/src/modeles/modeleFilms.php index 4cb8478..cf2d72d 100644 --- a/R3.01/tp/tp3/cinema/src/modeles/modeleFilms.php +++ b/R3.01/tp/tp3/cinema/src/modeles/modeleFilms.php @@ -1,25 +1,6 @@ Date: Wed, 15 Apr 2026 16:57:34 +0200 Subject: [PATCH 5/5] fix env example --- .env.example | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index cd5bda4..f6e1d42 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -CINEMA_DB_HOST=dwarves.iut-fbleau.fr -CINEMA_DB_USER=foo -CINEMA_DB_PASSWORD=foo -CINEMA_DB_NAME=foo \ No newline at end of file +DB_HOST=dwarves.iut-fbleau.fr +DB_USER=foo +DB_PASSWORD=foo +DB_NAME=foo \ No newline at end of file -- 2.54.0