Compare commits
3 Commits
main
..
17a16feb2d
| Author | SHA1 | Date | |
|---|---|---|---|
| 17a16feb2d | |||
| 553b30bdcc | |||
| 74ebab4b24 |
@@ -0,0 +1,4 @@
|
|||||||
|
CINEMA_DB_HOST=dwarves.iut-fbleau.fr
|
||||||
|
CINEMA_DB_USER=foo
|
||||||
|
CINEMA_DB_PASSWORD=foo
|
||||||
|
CINEMA_DB_NAME=foo
|
||||||
@@ -328,3 +328,4 @@ TSWLatexianTemp*
|
|||||||
# Uncomment the next line to have this generated file ignored.
|
# Uncomment the next line to have this generated file ignored.
|
||||||
#*Notes.bib
|
#*Notes.bib
|
||||||
|
|
||||||
|
.env
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<?php
|
<?php
|
||||||
echo "<h1>hello world !!!</h1>";
|
echo "<h1>hello world !!!</h1>";
|
||||||
phpinfo();
|
//phpinfo();
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ $clients = [
|
|||||||
"Arnaud"
|
"Arnaud"
|
||||||
];
|
];
|
||||||
|
|
||||||
var_dump($clients);
|
|
||||||
|
|
||||||
$produits = [
|
$produits = [
|
||||||
20 => "Chemise",
|
20 => "Chemise",
|
||||||
3 => "Pantalon",
|
3 => "Pantalon",
|
||||||
@@ -25,27 +23,4 @@ print_r($clients);
|
|||||||
print_r($produits);
|
print_r($produits);
|
||||||
print_r($array);
|
print_r($array);
|
||||||
echo "</pre>";
|
echo "</pre>";
|
||||||
|
|
||||||
// Exercice 2.1
|
|
||||||
$tab = [];
|
|
||||||
$somme = 0;
|
|
||||||
for ($i = 0; $i < 10; $i++) {
|
|
||||||
$somme += $i; // somme des entiers de 0 à i
|
|
||||||
$tab[$i] = $somme; // la clé i contient cette somme
|
|
||||||
}
|
|
||||||
print_r($tab);
|
|
||||||
|
|
||||||
|
|
||||||
// Exercice 2.2
|
|
||||||
for ($debut = 1; $debut <= 50; $debut += 10) {
|
|
||||||
echo "<p>";
|
|
||||||
for ($i = $debut; $i < $debut + 10; $i++) {
|
|
||||||
if ($i % 2 === 0) {
|
|
||||||
echo "<strong>$i</strong> ";
|
|
||||||
} else {
|
|
||||||
echo "<em>$i</em> ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo "</p>";
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once './include/data.inc.php';
|
include './include/data.inc.php';
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
@@ -28,26 +28,9 @@ include_once './include/data.inc.php';
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php include_once './include/data.inc.php'; ?>
|
|
||||||
<?php foreach ($data as $person) : ?>
|
|
||||||
<?php
|
|
||||||
$poids = (float) $person['Poids'];
|
|
||||||
$tailleM = (float) $person['Taille'] / 100;
|
|
||||||
|
|
||||||
$imc = null;
|
<!-- À compléter -->
|
||||||
if ($tailleM > 0) {
|
|
||||||
$imc = $poids / ($tailleM * $tailleM);
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<tr class="<?= $imc < 18.5 ? 'underweight' : ($imc < 25 ? 'normal' : 'warning') ?>">
|
|
||||||
<td><?= $person['Nom'] ?></td>
|
|
||||||
<td><?= $person['Prenom'] ?></td>
|
|
||||||
<td><?= $person['Email'] ?></td>
|
|
||||||
<td><?= $person['Taille'] ?></td>
|
|
||||||
<td><?= $person['Poids'] ?></td>
|
|
||||||
<td><?= round($imc, 2) ?></td>
|
|
||||||
</tr>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -1,19 +1,3 @@
|
|||||||
<?php
|
|
||||||
// Generate random values for two six-sided dice.
|
|
||||||
$die1 = mt_rand(1, 6);
|
|
||||||
$die2 = mt_rand(1, 6);
|
|
||||||
$sum = $die1 + $die2;
|
|
||||||
|
|
||||||
// Map dice values to matching SVG filenames.
|
|
||||||
$diceImages = [
|
|
||||||
1 => 'dice-six-faces-one.svg',
|
|
||||||
2 => 'dice-six-faces-two.svg',
|
|
||||||
3 => 'dice-six-faces-three.svg',
|
|
||||||
4 => 'dice-six-faces-four.svg',
|
|
||||||
5 => 'dice-six-faces-five.svg',
|
|
||||||
6 => 'dice-six-faces-six.svg',
|
|
||||||
];
|
|
||||||
?>
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
@@ -29,12 +13,12 @@ $diceImages = [
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<h5><a href="./">Tirage aléatoire</a></h5>
|
<h5><a href=""> Tirage aléatoire</a></h5>
|
||||||
<article class="is-center">
|
<article class="is-center">
|
||||||
<img src="./img/<?= $diceImages[$die1] ?>" alt="Dé 1 : <?= $die1 ?>">
|
<img src='./img/dice-six-faces-five.svg'>
|
||||||
<img src="./img/<?= $diceImages[$die2] ?>" alt="Dé 2 : <?= $die2 ?>">
|
<img src='./img/dice-six-faces-one.svg'>
|
||||||
</article>
|
</article>
|
||||||
<h5>Somme = <?= $sum ?></h5>
|
<h5>Somme = </h5>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once './include/favoris.inc.php';
|
include './include/favoris.inc.php';
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once './include/fonction.php';
|
include './include/fonction.php';
|
||||||
$alphabet = "@#!*^&azertyuiopqsdfghjkklmwxcvbnAZERTYUIOPLMKJHGFDSQWXCVBN1234567890";
|
$alphabet = "@#!*^&azertyuiopqsdfghjkklmwxcvbnAZERTYUIOPLMKJHGFDSQWXCVBN1234567890";
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once 'include/controller.php';
|
include 'include/controller.php';
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
<html lang="fr">
|
|
||||||
<head>
|
<head>
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
@@ -12,14 +11,14 @@ include_once 'include/controller.php';
|
|||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>Exercice 1</title>
|
<title></title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<ul>
|
<ul>
|
||||||
<?php
|
<?php
|
||||||
echo '<li>' . htmlspecialchars($prenom . ' ' . $nom, ENT_QUOTES, 'UTF-8') . '</li>';
|
echo "<li>$prenom $nom</li>";
|
||||||
echo '<li>' . htmlspecialchars($systeme, ENT_QUOTES, 'UTF-8') . " <i class='fa-brands $icon fa-2x'></i></li>";
|
echo "<li><i class='fa-brands $icon fa-2x'></i></li>";
|
||||||
?>
|
?>
|
||||||
</ul>
|
</ul>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -1,27 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// TODO
|
||||||
$nom = '';
|
|
||||||
$prenom = '';
|
|
||||||
$systeme = '';
|
|
||||||
$icon = 'fa-circle-question';
|
|
||||||
|
|
||||||
$systemes = [
|
|
||||||
1 => ['nom' => 'Linux', 'icon' => 'fa-linux'],
|
|
||||||
2 => ['nom' => 'Windows', 'icon' => 'fa-windows'],
|
|
||||||
3 => ['nom' => 'macOS', 'icon' => 'fa-apple'],
|
|
||||||
4 => ['nom' => 'Android', 'icon' => 'fa-android'],
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
||||||
$nomSaisi = trim((string) filter_input(INPUT_POST, 'nom', FILTER_UNSAFE_RAW));
|
|
||||||
$prenomSaisi = trim((string) filter_input(INPUT_POST, 'prenom', FILTER_UNSAFE_RAW));
|
|
||||||
$os = filter_input(INPUT_POST, 'os', FILTER_VALIDATE_INT);
|
|
||||||
|
|
||||||
$nom = ucfirst(strtolower($nomSaisi));
|
|
||||||
$prenom = ucfirst(strtolower($prenomSaisi));
|
|
||||||
|
|
||||||
if (isset($systemes[$os])) {
|
|
||||||
$systeme = $systemes[$os]['nom'];
|
|
||||||
$icon = $systemes[$os]['icon'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,18 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// TODO
|
||||||
$table = filter_input(INPUT_GET, 'table', FILTER_VALIDATE_INT);
|
|
||||||
|
|
||||||
$lignes = [];
|
|
||||||
$messageErreur = '';
|
|
||||||
|
|
||||||
if ($table === false || $table === null) {
|
|
||||||
$messageErreur = 'Veuillez saisir un entier valide.';
|
|
||||||
} else {
|
|
||||||
for ($multiplicateur = 1; $multiplicateur <= 10; $multiplicateur++) {
|
|
||||||
$lignes[] = [
|
|
||||||
'multiplicateur' => $multiplicateur,
|
|
||||||
'resultat' => $table * $multiplicateur,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once 'include/controller.php';
|
include 'include/controller.php';
|
||||||
?>
|
?>
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="fr">
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link
|
<link
|
||||||
@@ -10,38 +10,14 @@ include_once 'include/controller.php';
|
|||||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
<title>Exercice 2</title>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<h4>Table de multiplication</h4>
|
<h4>Table de multiplication</h4>
|
||||||
<form method="GET">
|
<form method="GET">
|
||||||
<input
|
<input type=number name="table" placeholder="table">
|
||||||
type="number"
|
|
||||||
name="table"
|
|
||||||
placeholder="table"
|
|
||||||
value="<?php echo htmlspecialchars($table, ENT_QUOTES, 'UTF-8'); ?>"
|
|
||||||
>
|
|
||||||
<button type="submit">ENVOYER</button>
|
<button type="submit">ENVOYER</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php if ($messageErreur !== '') : ?>
|
|
||||||
<p><?php echo htmlspecialchars($messageErreur, ENT_QUOTES, 'UTF-8'); ?></p>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ($table !== false && $table !== null) : ?>
|
|
||||||
<ul>
|
|
||||||
<?php foreach ($lignes as $ligne) : ?>
|
|
||||||
<li>
|
|
||||||
<?php echo htmlspecialchars((string) $table, ENT_QUOTES, 'UTF-8'); ?>
|
|
||||||
x
|
|
||||||
<?php echo htmlspecialchars((string) $ligne['multiplicateur'], ENT_QUOTES, 'UTF-8'); ?>
|
|
||||||
=
|
|
||||||
<?php echo htmlspecialchars((string) $ligne['resultat'], ENT_QUOTES, 'UTF-8'); ?>
|
|
||||||
</li>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</ul>
|
|
||||||
<?php endif; ?>
|
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once 'include/controller.php';
|
include 'include/controller.php';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>Exercice 3</title>
|
<title></title>
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico.min.css"
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
</head>
|
</head>
|
||||||
@@ -18,42 +18,17 @@ include_once 'include/controller.php';
|
|||||||
<h3>Calculatrice</h3>
|
<h3>Calculatrice</h3>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<input
|
<input placeholder="un nombre" type="number" step="any" name="op1" value ="" required>
|
||||||
placeholder="un nombre"
|
|
||||||
type="number"
|
|
||||||
step="any"
|
|
||||||
name="op1"
|
|
||||||
value="<?php echo htmlspecialchars($valeurOp1, ENT_QUOTES, 'UTF-8'); ?>"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<select name="operation" required>
|
<select name="operation" required>
|
||||||
<option value="+" <?php echo $operation === '+' ? 'selected' : ''; ?>>+</option>
|
<option value="+">+</option>
|
||||||
<option value="-" <?php echo $operation === '-' ? 'selected' : ''; ?>>-</option>
|
<option value="-">-</option>
|
||||||
<option value="x" <?php echo $operation === 'x' ? 'selected' : ''; ?>>x</option>
|
<option value="x">x</option>
|
||||||
<option value="/" <?php echo $operation === '/' ? 'selected' : ''; ?>>/</option>
|
<option value="/">/</option>
|
||||||
</select>
|
</select>
|
||||||
<input
|
<input placeholder="un nombre" type="number" step="any" name="op2" required>
|
||||||
placeholder="un nombre"
|
|
||||||
type="number"
|
|
||||||
step="any"
|
|
||||||
name="op2"
|
|
||||||
value="<?php echo htmlspecialchars($valeurOp2, ENT_QUOTES, 'UTF-8'); ?>"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<button type="submit" name="soumis"> Calculer</button>
|
<button type="submit" name="soumis"> Calculer</button>
|
||||||
</div>
|
</grid>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php if ($messageErreur !== '') : ?>
|
|
||||||
<p><?php echo htmlspecialchars($messageErreur, ENT_QUOTES, 'UTF-8'); ?></p>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ($aCalcule) : ?>
|
|
||||||
<p>
|
|
||||||
Résultat :
|
|
||||||
<?php echo htmlspecialchars($valeurOp1, ENT_QUOTES, 'UTF-8'); ?>
|
|
||||||
</p>
|
|
||||||
<?php endif; ?>
|
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,56 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//TODO
|
||||||
$op1Saisi = filter_input(INPUT_POST, 'op1', FILTER_UNSAFE_RAW);
|
|
||||||
$op2Saisi = filter_input(INPUT_POST, 'op2', FILTER_UNSAFE_RAW);
|
|
||||||
$operationSaisie = filter_input(INPUT_POST, 'operation', FILTER_UNSAFE_RAW);
|
|
||||||
|
|
||||||
$op1Saisi = is_string($op1Saisi) ? trim($op1Saisi) : '';
|
|
||||||
$op2Saisi = is_string($op2Saisi) ? trim($op2Saisi) : '';
|
|
||||||
$operationSaisie = is_string($operationSaisie) ? trim($operationSaisie) : '+';
|
|
||||||
|
|
||||||
$operationsAutorisees = ['+', '-', 'x', '/'];
|
|
||||||
$operation = in_array($operationSaisie, $operationsAutorisees, true) ? $operationSaisie : '+';
|
|
||||||
|
|
||||||
$resultat = null;
|
|
||||||
$messageErreur = '';
|
|
||||||
$aCalcule = false;
|
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
||||||
$op1 = filter_var($op1Saisi, FILTER_VALIDATE_FLOAT);
|
|
||||||
$op2 = filter_var($op2Saisi, FILTER_VALIDATE_FLOAT);
|
|
||||||
|
|
||||||
if ($op1 === false || $op2 === false) {
|
|
||||||
$messageErreur = 'Veuillez saisir deux nombres valides.';
|
|
||||||
} elseif (!in_array($operation, $operationsAutorisees, true)) {
|
|
||||||
$messageErreur = 'Veuillez choisir une opération valide.';
|
|
||||||
} elseif ($operation === '/' && (float) $op2 == 0.0) {
|
|
||||||
$messageErreur = 'La division par zéro est impossible.';
|
|
||||||
} else {
|
|
||||||
$aCalcule = true;
|
|
||||||
|
|
||||||
switch ($operation) {
|
|
||||||
case '+':
|
|
||||||
$resultat = $op1 + $op2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '-':
|
|
||||||
$resultat = $op1 - $op2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'x':
|
|
||||||
$resultat = $op1 * $op2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '/':
|
|
||||||
$resultat = $op1 / $op2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
$messageErreur = 'Veuillez choisir une opération valide.';
|
|
||||||
$aCalcule = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$valeurOp1 = $aCalcule ? (string) $resultat : $op1Saisi;
|
|
||||||
$valeurOp2 = $op2Saisi;
|
|
||||||
|
|||||||
@@ -2,13 +2,3 @@ button{
|
|||||||
|
|
||||||
float:right;
|
float:right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bonne-reponse {
|
|
||||||
color: #1b7f3a;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mauvaise-reponse {
|
|
||||||
color: #c62828;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,81 +1,17 @@
|
|||||||
<?php
|
|
||||||
$nombreQuestions = 0;
|
|
||||||
$score = 0;
|
|
||||||
$questionsTraitees = 0;
|
|
||||||
$message = 'Aucun resultat a afficher.';
|
|
||||||
$resultatsParQuestion = [];
|
|
||||||
|
|
||||||
$nombreQuestionsSaisi = filter_input(INPUT_POST, 'nbq', FILTER_VALIDATE_INT);
|
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $nombreQuestionsSaisi !== false && $nombreQuestionsSaisi !== null) {
|
|
||||||
$nombreQuestions = $nombreQuestionsSaisi;
|
|
||||||
$message = '';
|
|
||||||
|
|
||||||
for ($index = 1; $index <= $nombreQuestions; $index++) {
|
|
||||||
$reponse = filter_input(INPUT_POST, 'question' . $index, FILTER_UNSAFE_RAW);
|
|
||||||
|
|
||||||
if ($reponse !== null) {
|
|
||||||
$questionsTraitees++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($reponse === 'vrai') {
|
|
||||||
$score++;
|
|
||||||
$resultatsParQuestion[] = [
|
|
||||||
'numero' => $index,
|
|
||||||
'classe' => 'bonne-reponse',
|
|
||||||
'message' => 'Bonne reponse',
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$resultatsParQuestion[] = [
|
|
||||||
'numero' => $index,
|
|
||||||
'classe' => 'mauvaise-reponse',
|
|
||||||
'message' => 'Mauvaise reponse',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
||||||
/>
|
/>
|
||||||
<meta charset="UTF-8" />
|
<title></title>
|
||||||
<title>Exercice 4</title>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<h4>Resultat du quizz</h4>
|
<h4>Réponses</h4>
|
||||||
<?php if ($message !== '') : ?>
|
</div>
|
||||||
<p><?php echo htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); ?></p>
|
|
||||||
<?php else : ?>
|
|
||||||
<p>
|
|
||||||
Vous avez obtenu
|
|
||||||
<?php echo htmlspecialchars((string) $score, ENT_QUOTES, 'UTF-8'); ?>
|
|
||||||
bonne(s) reponse(s) sur
|
|
||||||
<?php echo htmlspecialchars((string) $nombreQuestions, ENT_QUOTES, 'UTF-8'); ?>.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Questions repondues :
|
|
||||||
<?php echo htmlspecialchars((string) $questionsTraitees, ENT_QUOTES, 'UTF-8'); ?>.
|
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<?php foreach ($resultatsParQuestion as $resultatQuestion) : ?>
|
|
||||||
<li>
|
|
||||||
Question <?php echo htmlspecialchars((string) $resultatQuestion['numero'], ENT_QUOTES, 'UTF-8'); ?> :
|
|
||||||
<span class="<?php echo htmlspecialchars($resultatQuestion['classe'], ENT_QUOTES, 'UTF-8'); ?>">
|
|
||||||
<?php echo htmlspecialchars($resultatQuestion['message'], ENT_QUOTES, 'UTF-8'); ?>
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</ul>
|
|
||||||
<?php endif; ?>
|
|
||||||
<p>
|
|
||||||
<a href="quizz.html">Revenir au quizz</a>
|
|
||||||
</p>
|
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once 'include/controller.php';
|
include 'include/controller.php';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link
|
<link
|
||||||
@@ -11,35 +11,13 @@ include_once 'include/controller.php';
|
|||||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
<title>Exercice 5</title>
|
|
||||||
|
<title></title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<h3>Conjugaison</h3>
|
|
||||||
|
|
||||||
<?php if ($messageErreur !== '') : ?>
|
|
||||||
<p><?php echo htmlspecialchars($messageErreur, ENT_QUOTES, 'UTF-8'); ?></p>
|
|
||||||
<?php else : ?>
|
|
||||||
<p>
|
|
||||||
Verbe :
|
|
||||||
<?php echo htmlspecialchars($verbe, ENT_QUOTES, 'UTF-8'); ?>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<?php foreach ($conjugaisons as $conjugaison) : ?>
|
|
||||||
<section>
|
|
||||||
<h4><?php echo htmlspecialchars($conjugaison['temps'], ENT_QUOTES, 'UTF-8'); ?></h4>
|
|
||||||
<ul>
|
|
||||||
<?php foreach ($conjugaison['formes'] as $forme) : ?>
|
|
||||||
<li><?php echo htmlspecialchars($forme, ENT_QUOTES, 'UTF-8'); ?></li>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</ul>
|
|
||||||
</section>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<a href="ex5.html">Retour au formulaire</a>
|
|
||||||
</p>
|
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,64 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
$terminaisons = array(
|
$terminaisons = array(
|
||||||
'present' => array('e', 'es', 'e', 'ons', 'ez', 'ent'),
|
"present"=>array("e","es","e","ons","ez","ent"),
|
||||||
'futur' => array('erai', 'eras', 'era', 'erons', 'erez', 'eront'),
|
"futur"=>array("erai","eras","era","erons","erez","eront"),
|
||||||
'imparfait' => array('ais', 'ais', 'ait', 'ions', 'iez', 'aient')
|
"imparfait"=>array("ais","ais","ait","ions","iez","aient")
|
||||||
);
|
);
|
||||||
|
|
||||||
$libellesTemps = array(
|
$pronoms=array("je","tu","il","nous","vous","ils");
|
||||||
'present' => 'Present',
|
|
||||||
'futur' => 'Futur',
|
|
||||||
'imparfait' => 'Imparfait'
|
|
||||||
);
|
|
||||||
|
|
||||||
$pronoms = array('je', 'tu', 'il', 'nous', 'vous', 'ils');
|
$verbe = filter_input(INPUT_POST,"verbe",FILTER_SANITIZE_STRING);
|
||||||
|
|
||||||
$verbeSaisi = filter_input(INPUT_POST, 'verbe', FILTER_UNSAFE_RAW);
|
|
||||||
$verbeSaisi = is_string($verbeSaisi) ? trim($verbeSaisi) : '';
|
|
||||||
$verbe = strtolower($verbeSaisi);
|
|
||||||
|
|
||||||
$tempsChoisis = filter_input(INPUT_POST, 'temps', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
|
|
||||||
$tempsChoisis = is_array($tempsChoisis) ? $tempsChoisis : array();
|
|
||||||
|
|
||||||
$messageErreur = '';
|
|
||||||
$conjugaisons = array();
|
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
||||||
if ($verbe === '') {
|
|
||||||
$messageErreur = 'Veuillez saisir un verbe.';
|
|
||||||
} elseif (strlen($verbe) < 3 || substr($verbe, -2) !== 'er') {
|
|
||||||
$messageErreur = 'Veuillez saisir un verbe du premier groupe.';
|
|
||||||
} elseif ($tempsChoisis === array()) {
|
|
||||||
$messageErreur = 'Veuillez choisir au moins un temps.';
|
|
||||||
} else {
|
|
||||||
$radical = substr($verbe,0,strlen($verbe)-2);
|
$radical = substr($verbe,0,strlen($verbe)-2);
|
||||||
|
|
||||||
foreach ($tempsChoisis as $temps) {
|
|
||||||
if (!isset($terminaisons[$temps], $libellesTemps[$temps])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$formes = array();
|
|
||||||
|
|
||||||
foreach ($pronoms as $index => $pronom) {
|
|
||||||
$forme = $radical . $terminaisons[$temps][$index];
|
|
||||||
|
|
||||||
if ($pronom === 'je' && preg_match('/^[aeiouh]/', $forme) === 1) {
|
|
||||||
$formes[] = "j'" . $forme;
|
|
||||||
} else {
|
|
||||||
$formes[] = $pronom . ' ' . $forme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$conjugaisons[] = array(
|
|
||||||
'temps' => $libellesTemps[$temps],
|
|
||||||
'formes' => $formes
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($conjugaisons === array()) {
|
|
||||||
$messageErreur = 'Aucun temps valide n a ete transmis.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,3 @@ color:#2E8B57;
|
|||||||
.Loss{
|
.Loss{
|
||||||
color:#FF6347;
|
color:#FF6347;
|
||||||
}
|
}
|
||||||
.Draw{
|
|
||||||
color:#DAA520;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,35 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
$ROCK = 0;
|
|
||||||
$PAPER = 1;
|
|
||||||
$SCISSORS = 2;
|
|
||||||
|
|
||||||
$images = ["rock.png","paper.png","scissors.png"];
|
$images = ["rock.png","paper.png","scissors.png"];
|
||||||
$rules = [
|
$isPlaying = true;
|
||||||
$ROCK => [$ROCK => "Draw", $PAPER => "Loss", $SCISSORS => "Win"],
|
|
||||||
$PAPER => [$ROCK => "Win", $PAPER => "Draw", $SCISSORS => "Loss"],
|
|
||||||
$SCISSORS => [$ROCK => "Loss", $PAPER => "Win", $SCISSORS => "Draw"],
|
|
||||||
];
|
|
||||||
|
|
||||||
$playerChoice = filter_input(
|
$playerChoice = 0;
|
||||||
INPUT_GET,
|
$computerChoice = 1;
|
||||||
'choice',
|
|
||||||
FILTER_VALIDATE_INT,
|
|
||||||
['options' => ['min_range' => 0, 'max_range' => 2]]
|
|
||||||
);
|
|
||||||
|
|
||||||
$isPlaying = ($playerChoice !== null && $playerChoice !== false);
|
$message = "Win";
|
||||||
|
$class = "Win";
|
||||||
|
|
||||||
if ($isPlaying) {
|
|
||||||
$computerChoice = mt_rand(0, 2);
|
|
||||||
$message = $rules[$playerChoice][$computerChoice];
|
|
||||||
$class = $message;
|
|
||||||
$imagePlayer = $images[$playerChoice];
|
$imagePlayer = $images[$playerChoice];
|
||||||
$imageComputer = $images[$computerChoice];
|
$imageComputer = $images[$computerChoice];
|
||||||
}
|
|
||||||
|
|
||||||
include_once './views/header.php';
|
include './views/header.php';
|
||||||
if ($isPlaying){
|
if ($isPlaying){
|
||||||
include_once './views/game.php';
|
include './views/game.php';
|
||||||
include_once './views/message.php';
|
include './views/message.php';
|
||||||
}
|
}
|
||||||
include_once './views/footer.php';
|
include './views/footer.php';
|
||||||
|
?>
|
||||||
|
|||||||
@@ -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`
|
-- Table structure for table `Artiste`
|
||||||
--
|
--
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
$login = isset($_GET['login']) ? trim($_GET['login']) : '';
|
||||||
|
$error = isset($_GET['error']);
|
||||||
|
$registered = isset($_GET['registered']);
|
||||||
|
$loggedOut = isset($_GET['logged_out']);
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Authentification</title>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
|
<h1>Authentification</h1>
|
||||||
|
|
||||||
|
<?php if ($registered) { ?>
|
||||||
|
<article>Inscription réussie. Vous pouvez maintenant vous connecter.</article>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<?php if ($loggedOut) { ?>
|
||||||
|
<article>Vous avez été déconnecté.</article>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<?php if ($error) { ?>
|
||||||
|
<article aria-invalid="true">Login ou mot de passe incorrect.</article>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<form action="./verification.php" method="post">
|
||||||
|
<label for="login">Login</label>
|
||||||
|
<input id="login" name="login" value="<?php echo htmlspecialchars($login, ENT_QUOTES); ?>">
|
||||||
|
|
||||||
|
<label for="password">Mot de passe</label>
|
||||||
|
<input id="password" name="password" type="password">
|
||||||
|
|
||||||
|
<button type="submit">Se connecter</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p><a href="./inscription.php">Créer un compte</a></p>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
$_SESSION = array();
|
||||||
|
|
||||||
|
if (ini_get('session.use_cookies')) {
|
||||||
|
$params = session_get_cookie_params();
|
||||||
|
setcookie(session_name(), '', time() - 3600, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
|
||||||
|
}
|
||||||
|
|
||||||
|
session_destroy();
|
||||||
|
|
||||||
|
header('Location: ./authentification.php?logged_out=1');
|
||||||
|
exit;
|
||||||
@@ -1,34 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
include_once './securite.php';
|
||||||
include_once './modeles/modeleFilms.php';
|
include_once './modeles/modeleFilms.php';
|
||||||
|
|
||||||
$currentPage = filter_input(
|
$films = getFilms();
|
||||||
INPUT_GET,
|
|
||||||
'page',
|
|
||||||
FILTER_VALIDATE_INT,
|
|
||||||
['options' => ['min_range' => 1]]
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($currentPage === null || $currentPage === false) {
|
|
||||||
$currentPage = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$perPage = 10;
|
|
||||||
$data = getFilms($currentPage, $perPage);
|
|
||||||
$films = $data['films'];
|
|
||||||
$errorMessage = $data['error'];
|
|
||||||
$totalFilms = $data['total'];
|
|
||||||
$totalPages = max(1, (int) ceil($totalFilms / $perPage));
|
|
||||||
|
|
||||||
if ($currentPage > $totalPages && $totalFilms > 0) {
|
|
||||||
$currentPage = $totalPages;
|
|
||||||
$data = getFilms($currentPage, $perPage);
|
|
||||||
$films = $data['films'];
|
|
||||||
$errorMessage = $data['error'];
|
|
||||||
$totalFilms = $data['total'];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// on "charge" la vue
|
// On charge les fichiers de vue une fois les données prêtes.
|
||||||
//
|
//
|
||||||
|
|
||||||
include_once './vues/header.php';
|
include_once './vues/header.php';
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
include_once './modeles/modeleUtilisateurs.php';
|
||||||
|
|
||||||
|
$errors = array();
|
||||||
|
$values = array(
|
||||||
|
'login' => '',
|
||||||
|
'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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Inscription</title>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
|
<h1>Inscription</h1>
|
||||||
|
<p>Créez un compte avant d'accéder aux pages du site.</p>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<label for="login">Login</label>
|
||||||
|
<input
|
||||||
|
id="login"
|
||||||
|
name="login"
|
||||||
|
value="<?php echo htmlspecialchars($values['login'], ENT_QUOTES); ?>"
|
||||||
|
>
|
||||||
|
<?php if (isset($errors['login'])) { ?>
|
||||||
|
<small><?php echo htmlspecialchars($errors['login'], ENT_QUOTES); ?></small>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<label for="email">Email</label>
|
||||||
|
<input
|
||||||
|
id="email"
|
||||||
|
name="email"
|
||||||
|
type="email"
|
||||||
|
value="<?php echo htmlspecialchars($values['email'], ENT_QUOTES); ?>"
|
||||||
|
>
|
||||||
|
<?php if (isset($errors['email'])) { ?>
|
||||||
|
<small><?php echo htmlspecialchars($errors['email'], ENT_QUOTES); ?></small>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<label for="password">Mot de passe</label>
|
||||||
|
<input id="password" name="password" type="password">
|
||||||
|
<?php if (isset($errors['password'])) { ?>
|
||||||
|
<small><?php echo htmlspecialchars($errors['password'], ENT_QUOTES); ?></small>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<button type="submit">S'inscrire</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p><a href="./authentification.php">Déjà inscrit ? Se connecter</a></p>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
function getConnection()
|
||||||
|
{
|
||||||
|
static $conn = null;
|
||||||
|
|
||||||
|
if ($conn !== null) {
|
||||||
|
return $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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') : '';
|
||||||
|
|
||||||
|
if ($user === '' || $database === '') {
|
||||||
|
die(
|
||||||
|
"Configurez d'abord l'accès MySQL dans modeles/connexion.php " .
|
||||||
|
"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());
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_set_charset($conn, 'utf8mb4');
|
||||||
|
|
||||||
|
return $conn;
|
||||||
|
}
|
||||||
@@ -1,69 +1,28 @@
|
|||||||
<?php
|
<?php
|
||||||
function getConnection()
|
include_once __DIR__ . '/connexion.php';
|
||||||
{
|
|
||||||
static $conn = null;
|
|
||||||
|
|
||||||
if ($conn === null) {
|
function getFilms()
|
||||||
$host = getenv('DB_HOST') ?: 'https://dwarves.iut-fbleau.fr';
|
|
||||||
$login = getenv('DB_USER') ?: getenv('USER') ?: getenv('USERNAME') ?: 'root';
|
|
||||||
$password = getenv('DB_PASSWORD') ?: $login;
|
|
||||||
$database = getenv('DB_NAME') ?: $login;
|
|
||||||
$conn = mysqli_connect($host, $login, $password, $database);
|
|
||||||
|
|
||||||
if ($conn !== false) {
|
|
||||||
mysqli_set_charset($conn, 'utf8mb4');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFilms($page = 1, $perPage = 10)
|
|
||||||
{
|
{
|
||||||
$conn = getConnection();
|
$conn = getConnection();
|
||||||
if ($conn === false) {
|
$sql = "
|
||||||
return [
|
SELECT Film.idFilm, Film.titre, Film.annee, Genre.code AS genre, Artiste.nom, Artiste.prenom
|
||||||
'films' => [],
|
FROM Film
|
||||||
'total' => 0,
|
JOIN Genre ON Genre.code = Film.genre
|
||||||
'error' => 'Connexion MySQL impossible.',
|
JOIN Artiste ON Artiste.idArtiste = Film.idMes
|
||||||
];
|
ORDER BY Film.titre ASC
|
||||||
}
|
";
|
||||||
|
|
||||||
$page = max(1, (int) $page);
|
|
||||||
$perPage = max(1, (int) $perPage);
|
|
||||||
$offset = ($page - 1) * $perPage;
|
|
||||||
|
|
||||||
$sql = "SELECT SQL_CALC_FOUND_ROWS
|
|
||||||
F.idFilm,
|
|
||||||
F.titre,
|
|
||||||
F.annee,
|
|
||||||
G.code AS genre,
|
|
||||||
A.prenom,
|
|
||||||
A.nom
|
|
||||||
FROM Film AS F
|
|
||||||
INNER JOIN Artiste AS A ON F.idMes = A.idArtiste
|
|
||||||
INNER JOIN Genre AS G ON F.genre = G.code
|
|
||||||
ORDER BY F.titre ASC
|
|
||||||
LIMIT {$offset}, {$perPage}";
|
|
||||||
|
|
||||||
$result = mysqli_query($conn, $sql);
|
$result = mysqli_query($conn, $sql);
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
return [
|
die('Erreur SQL lors de la récupération des films : ' . mysqli_error($conn));
|
||||||
'films' => [],
|
|
||||||
'total' => 0,
|
|
||||||
'error' => 'Exécution de la requête impossible.',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$films = mysqli_fetch_all($result, MYSQLI_ASSOC);
|
$films = array();
|
||||||
|
while ($film = mysqli_fetch_assoc($result)) {
|
||||||
|
$films[] = $film;
|
||||||
|
}
|
||||||
|
|
||||||
$totalResult = mysqli_query($conn, 'SELECT FOUND_ROWS() AS total');
|
mysqli_free_result($result);
|
||||||
$totalRow = $totalResult ? mysqli_fetch_assoc($totalResult) : ['total' => 0];
|
|
||||||
$total = isset($totalRow['total']) ? (int) $totalRow['total'] : 0;
|
|
||||||
|
|
||||||
return [
|
return $films;
|
||||||
'films' => $films,
|
|
||||||
'total' => $total,
|
|
||||||
'error' => null,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
include_once __DIR__ . '/connexion.php';
|
||||||
|
|
||||||
|
function findUserByLogin($login)
|
||||||
|
{
|
||||||
|
$conn = getConnection();
|
||||||
|
$stmt = mysqli_prepare($conn, 'SELECT login, email, password FROM `user` WHERE login = ?');
|
||||||
|
if ($stmt === false) {
|
||||||
|
die('Préparation SQL impossible : ' . mysqli_error($conn));
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_stmt_bind_param($stmt, 's', $login);
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
mysqli_stmt_bind_result($stmt, $dbLogin, $dbEmail, $dbPassword);
|
||||||
|
|
||||||
|
$user = null;
|
||||||
|
if (mysqli_stmt_fetch($stmt)) {
|
||||||
|
$user = array(
|
||||||
|
'login' => $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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ce fichier est inclus en tête de chaque page protégée.
|
||||||
|
// Si l'utilisateur n'est pas connecté, on le renvoie vers le formulaire.
|
||||||
|
if (!isset($_SESSION['user_login'])) {
|
||||||
|
header('Location: ./authentification.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
include_once './modeles/modeleUtilisateurs.php';
|
||||||
|
|
||||||
|
$login = isset($_POST['login']) ? trim($_POST['login']) : '';
|
||||||
|
$password = isset($_POST['password']) ? $_POST['password'] : '';
|
||||||
|
|
||||||
|
// Cette temporisation ralentit volontairement les tentatives répétées,
|
||||||
|
// ce qui rend les attaques par force brute moins efficaces.
|
||||||
|
usleep(500000);
|
||||||
|
|
||||||
|
if ($login === '' || $password === '') {
|
||||||
|
header('Location: ./authentification.php?error=1&login=' . urlencode($login));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = findUserByLogin($login);
|
||||||
|
|
||||||
|
if ($user === null) {
|
||||||
|
header('Location: ./authentification.php?error=1&login=' . urlencode($login));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!password_verify($password, $user['password'])) {
|
||||||
|
header('Location: ./authentification.php?error=1&login=' . urlencode($login));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
session_regenerate_id(true);
|
||||||
|
$_SESSION['user_login'] = $user['login'];
|
||||||
|
$_SESSION['user_email'] = $user['email'];
|
||||||
|
|
||||||
|
header('Location: ./films.php');
|
||||||
|
exit;
|
||||||
@@ -12,3 +12,13 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main class="container">
|
<main class="container">
|
||||||
|
<nav>
|
||||||
|
<ul>
|
||||||
|
<li><strong>Cinema</strong></li>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><a href="./films.php">Films</a></li>
|
||||||
|
<li>Connecté : <?php echo htmlspecialchars(isset($_SESSION['user_login']) ? $_SESSION['user_login'] : 'inconnu', ENT_QUOTES); ?></li>
|
||||||
|
<li><a href="./deconnexion.php">Déconnexion</a></li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|||||||
@@ -4,9 +4,6 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<h2>Films</h2>
|
<h2>Films</h2>
|
||||||
<?php if (!empty($errorMessage)) { ?>
|
|
||||||
<article><?php echo htmlspecialchars($errorMessage, ENT_QUOTES, 'UTF-8'); ?></article>
|
|
||||||
<?php } ?>
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -19,46 +16,17 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php
|
<?php
|
||||||
foreach($films as $film){
|
foreach($films as $film){
|
||||||
$titre = htmlspecialchars($film['titre'], ENT_QUOTES, 'UTF-8');
|
|
||||||
$annee = htmlspecialchars((string) $film['annee'], ENT_QUOTES, 'UTF-8');
|
|
||||||
$genre = htmlspecialchars($film['genre'], ENT_QUOTES, 'UTF-8');
|
|
||||||
$realisateur = htmlspecialchars($film['prenom'] . ' ' . $film['nom'], ENT_QUOTES, 'UTF-8');
|
|
||||||
|
|
||||||
echo "
|
echo "
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href='#'>{$titre}</a></td>
|
<td><a href='#'>{$film['titre']}</a></td>
|
||||||
<td>{$annee}</td>
|
<td>{$film['annee']}</td>
|
||||||
<td>{$genre}</td>
|
<td>{$film['genre']}</td>
|
||||||
<td>{$realisateur}</td>
|
<td>{$film['prenom']} {$film['nom']}</td>
|
||||||
</tr>";
|
</tr>";
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php if ($totalPages > 1) { ?>
|
|
||||||
<nav>
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<?php if ($currentPage > 1) { ?>
|
|
||||||
<a href="?page=<?php echo $currentPage - 1; ?>">Précédent</a>
|
|
||||||
<?php } else { ?>
|
|
||||||
<span>Précédent</span>
|
|
||||||
<?php } ?>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<ul>
|
|
||||||
<li>Page <?php echo $currentPage; ?> / <?php echo $totalPages; ?></li>
|
|
||||||
</ul>
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<?php if ($currentPage < $totalPages) { ?>
|
|
||||||
<a href="?page=<?php echo $currentPage + 1; ?>">Suivant</a>
|
|
||||||
<?php } else { ?>
|
|
||||||
<span>Suivant</span>
|
|
||||||
<?php } ?>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
<?php } ?>
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
$osSet = ['linux','apple','windows'];
|
// Les valeurs autorisées servent à la fois pour la validation
|
||||||
$os = "linux";
|
// du formulaire et pour l'affichage dans la vue.
|
||||||
|
$osSet = [
|
||||||
|
'linux' => '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';
|
||||||
|
|||||||
@@ -1,43 +1,49 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<title>Cookie OS préféré</title>
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main class="container">
|
<main class="container">
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<fieldset class="grid">
|
<fieldset class="grid">
|
||||||
<legend>Changez votre os</legend>
|
<legend>Changez votre os</legend>
|
||||||
|
<?php foreach ($osSet as $value => $label) { ?>
|
||||||
<label>
|
<label>
|
||||||
<input type="radio" name="os" value="linux">
|
<input
|
||||||
<i class="fa fa-linux fa-2x" aria-hidden="true"></i>
|
type="radio"
|
||||||
</label>
|
name="os"
|
||||||
<label>
|
value="<?php echo htmlspecialchars($value, ENT_QUOTES); ?>"
|
||||||
<input type="radio" name="os" value="windows">
|
<?php echo $os === $value ? 'checked' : ''; ?>
|
||||||
<i class="fa fa-windows fa-2x" aria-hidden="true"></i>
|
>
|
||||||
</label>
|
<i class="fa fa-<?php echo htmlspecialchars($value, ENT_QUOTES); ?> fa-2x" aria-hidden="true"></i>
|
||||||
<label>
|
<?php echo htmlspecialchars($label, ENT_QUOTES); ?>
|
||||||
<input type="radio" name="os" value="apple">
|
|
||||||
<i class="fa fa-apple fa-2x" aria-hidden="true"></i>
|
|
||||||
</label>
|
</label>
|
||||||
|
<?php } ?>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<button type="submit">Envoyer</button>
|
<button type="submit">Envoyer</button>
|
||||||
</form>
|
</form>
|
||||||
<article>
|
<article>
|
||||||
<header>Votre os</header>
|
<header>Votre os</header>
|
||||||
<?php echo "<i class='fa fa-$os fa-5x'></i>";?>
|
<p>
|
||||||
|
<!-- On affiche l'icône et le nom de l'OS courant. -->
|
||||||
|
<i class="fa fa-<?php echo htmlspecialchars($os, ENT_QUOTES); ?> fa-5x" aria-hidden="true"></i>
|
||||||
|
</p>
|
||||||
|
<p><?php echo htmlspecialchars($osSet[$os], ENT_QUOTES); ?></p>
|
||||||
<footer>
|
<footer>
|
||||||
Rafraîchir la page <a href=""><i class="fa fa-refresh" aria-hidden="true"></i></a>
|
Rafraîchir la page
|
||||||
|
<a href="./" aria-label="Rafraîchir la page">
|
||||||
|
<i class="fa fa-refresh" aria-hidden="true"></i>
|
||||||
|
</a>
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,54 +1,83 @@
|
|||||||
<?php
|
<?php
|
||||||
|
function initializeGame()
|
||||||
|
{
|
||||||
|
// Une grille vide contient 9 cases valant 0.
|
||||||
|
$_SESSION['grid'] = array_fill(0, 9, 0);
|
||||||
|
$_SESSION['playerTurn'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function nextPlayer($player)
|
||||||
|
{
|
||||||
|
return $player === 1 ? 2 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
function isWinner($grid, $player)
|
function isWinner($grid, $player)
|
||||||
{
|
{
|
||||||
$winStates = array
|
$winStates = array(
|
||||||
(
|
array(0, 1, 2), array(3, 4, 5), array(6, 7, 8),
|
||||||
array(0, 1, 2), array(3, 4, 5), array(6, 7, 8), // Horizontal
|
array(0, 3, 6), array(1, 4, 7), array(2, 5, 8),
|
||||||
array(0, 3, 6), array(1, 4, 7), array(2, 5, 8), // Vertical
|
array(0, 4, 8), array(2, 4, 6)
|
||||||
array(0, 4, 8), array(2, 4, 6) // Diagonal
|
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($winStates as $winState)
|
foreach ($winStates as $winState) {
|
||||||
{
|
if (
|
||||||
if ($grid[$winState[0]] == $player &&
|
$grid[$winState[0]] == $player &&
|
||||||
$grid[$winState[1]] == $player &&
|
$grid[$winState[1]] == $player &&
|
||||||
$grid[$winState[2]] == $player)
|
$grid[$winState[2]] == $player
|
||||||
{
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function noWinner($grid)
|
function noWinner($grid)
|
||||||
{
|
{
|
||||||
for($i = 0; $i < 9; $i++)
|
for ($i = 0; $i < 9; $i++) {
|
||||||
if ($grid[$i] == 0)
|
if ($grid[$i] == 0) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayGrid($grid)
|
function getWinner($grid)
|
||||||
|
{
|
||||||
|
if (isWinner($grid, 1)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isWinner($grid, 2)) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayGrid($grid, $isInteractive = true)
|
||||||
{
|
{
|
||||||
echo '<table class="morpion">';
|
echo '<table class="morpion">';
|
||||||
for ($i = 0; $i < 3; $i++) {
|
for ($i = 0; $i < 3; $i++) {
|
||||||
echo "<tr>";
|
echo '<tr>';
|
||||||
for ($j = 0; $j < 3; $j++) {
|
for ($j = 0; $j < 3; $j++) {
|
||||||
|
echo '<td>';
|
||||||
echo "<td>";
|
|
||||||
|
|
||||||
$pos = 3 * $i + $j;
|
$pos = 3 * $i + $j;
|
||||||
if ($grid[$pos] == 0)
|
if ($grid[$pos] == 0 && $isInteractive) {
|
||||||
echo "<a href='?pos=$pos'></a>";
|
echo "<a href='?pos=$pos'></a>";
|
||||||
if ($grid[$pos] == 1)
|
}
|
||||||
|
if ($grid[$pos] == 1) {
|
||||||
echo '<i class="fa fa-times" aria-hidden="true"></i>';
|
echo '<i class="fa fa-times" aria-hidden="true"></i>';
|
||||||
if ($grid[$pos] == 2)
|
}
|
||||||
|
if ($grid[$pos] == 2) {
|
||||||
echo '<i class="fa fa-circle-o" aria-hidden="true"></i>';
|
echo '<i class="fa fa-circle-o" aria-hidden="true"></i>';
|
||||||
|
}
|
||||||
|
|
||||||
echo "</td>";
|
echo '</td>';
|
||||||
}
|
}
|
||||||
echo "</tr>";
|
echo '</tr>';
|
||||||
}
|
}
|
||||||
echo "</table>";
|
echo '</table>';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,70 @@
|
|||||||
<?php
|
<?php
|
||||||
include 'helpers.php';
|
session_start();
|
||||||
|
|
||||||
// view variables
|
include_once 'helpers.php';
|
||||||
$message = "";
|
|
||||||
$grid = [0,1,0,1,0,2,2,0,0];
|
|
||||||
$playerTurn = 1; // 1 or 2
|
|
||||||
|
|
||||||
|
// Si on demande une nouvelle partie, on réinitialise l'état stocké
|
||||||
|
// en session puis on recharge la page sans paramètre.
|
||||||
|
if (isset($_GET['reset'])) {
|
||||||
|
initializeGame();
|
||||||
|
header('Location: .');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
include './views/tictactoe.php';
|
if (!isset($_SESSION['grid']) || !isset($_SESSION['playerTurn'])) {
|
||||||
|
initializeGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Variables transmises à la vue.
|
||||||
|
$message = '';
|
||||||
|
$grid = $_SESSION['grid'];
|
||||||
|
$playerTurn = (int) $_SESSION['playerTurn'];
|
||||||
|
|
||||||
|
$winner = getWinner($grid);
|
||||||
|
$isGameOver = $winner !== 0 || noWinner($grid);
|
||||||
|
|
||||||
|
// On joue uniquement si la partie est encore en cours.
|
||||||
|
if (!$isGameOver && isset($_GET['pos'])) {
|
||||||
|
$pos = filter_input(
|
||||||
|
INPUT_GET,
|
||||||
|
'pos',
|
||||||
|
FILTER_VALIDATE_INT,
|
||||||
|
array('options' => 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';
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,34 @@
|
|||||||
<html>
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<title>Tic Tac Toe</title>
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main class="container center">
|
<main class="container center">
|
||||||
<h4>Tic Tac Toe : <?php echo "player $playerTurn turn";?></h4>
|
<h4>
|
||||||
|
<?php if ($isGameOver) { ?>
|
||||||
|
Partie terminée
|
||||||
|
<?php } else { ?>
|
||||||
|
Tic Tac Toe : joueur <?php echo $playerTurn; ?> à vous de jouer
|
||||||
|
<?php } ?>
|
||||||
|
</h4>
|
||||||
<?php
|
<?php
|
||||||
displayGrid($grid);
|
// Quand la partie est finie, les liens dans les cases vides
|
||||||
|
// disparaissent pour empêcher tout coup supplémentaire.
|
||||||
|
displayGrid($grid, !$isGameOver);
|
||||||
|
|
||||||
if ($message != "")
|
if ($message != '') {
|
||||||
echo "<h5>$message <a href='.'>new game</a></h5>";
|
echo '<h5>' . htmlspecialchars($message, ENT_QUOTES) . " <a href='?reset=1'>nouvelle partie</a></h5>";
|
||||||
|
} else {
|
||||||
|
echo "<p><a href='?reset=1'>Recommencer la partie</a></p>";
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user