Compare commits
6 Commits
11386eed58
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a4580652f8 | |||
| 045ec81ae2 | |||
| 3c100c0200 | |||
| 5ef7c7b630 | |||
| c165b74c99 | |||
| 91524fb5e5 |
@@ -30,9 +30,12 @@ Les notions suivantes seront abordées :
|
|||||||
|
|
||||||
| Semaine | Cours | TD/TP |
|
| Semaine | Cours | TD/TP |
|
||||||
| ------------------ | -------------------------------------------------------- | ------------------ |
|
| ------------------ | -------------------------------------------------------- | ------------------ |
|
||||||
| 1 : 16/03 - 20/03| [Bases du langages](./cours/cm_bases_php.pdf) | |
|
| 1 | [Bases du langages](./cours/cm_bases_php.pdf) | |
|
||||||
| 2 : 23/03 - 27/03 | | [tp1](./tp/tp1) |
|
| 2 | | [tp1](./tp/tp1) |
|
||||||
| 3 : 30/03 - 03/04 | [Intéractions avec le client](./cours/cm_interaction_client_serveur.pdf) | [tp2](./tp/tp2) |
|
| 3 | [Intéractions avec le client](./cours/cm_interaction_client_serveur.pdf) | [tp2](./tp/tp2) |
|
||||||
|
| 4 | [PHP/MySQL](./cours/cm_extension_mysqli.pdf) | [tp3](./tp/tp3) |
|
||||||
|
| 5 | [Cookies et sessions](./cours/cm_cookies_sessions.pdf) | [tp3](./tp/tp3) , [tp4](./tp/tp4) |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Les TPS
|
## Les TPS
|
||||||
@@ -49,4 +52,18 @@ aborde la récupération des données de formulaires avec PHP.
|
|||||||
À chaque exercice correspond un sous répertoire avec
|
À chaque exercice correspond un sous répertoire avec
|
||||||
des fichiers à compléter.
|
des fichiers à compléter.
|
||||||
|
|
||||||
|
#### TP3 : PHP/Mysql
|
||||||
|
Le [tp3](./tp/tp3)
|
||||||
|
aborde l'interfaçage de php avec mysql, au moyen de l'extention
|
||||||
|
[mysqli](http://php.net/manual/fr/book.mysqli.php) de php.
|
||||||
|
À chaque exercice correspond un sous répertoire avec
|
||||||
|
des fichiers à compléter.
|
||||||
|
|
||||||
|
#### TP4 : Cookies et sessions
|
||||||
|
Le [tp4](./tp/tp4)
|
||||||
|
aborde la notion de cookies et de sessions,et
|
||||||
|
les fonctions php dédiées.
|
||||||
|
À chaque exercice correspond un sous répertoire avec
|
||||||
|
des fichiers à compléter.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<?php
|
<?php
|
||||||
echo "<h1>hello world !!!</h1>";
|
echo "<h1>hello world !!!</h1>";
|
||||||
//phpinfo();
|
phpinfo();
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
$clients = [
|
$clients = [
|
||||||
"Luc",
|
"Luc",
|
||||||
7 => "Paul",
|
7 => "Paul",
|
||||||
2 =>"Martin",
|
2 =>"Martin",
|
||||||
"Arnaud"
|
"Arnaud"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var_dump($clients);
|
||||||
|
|
||||||
$produits = [
|
$produits = [
|
||||||
20 => "Chemise",
|
20 => "Chemise",
|
||||||
3 => "Pantalon",
|
3 => "Pantalon",
|
||||||
10 => "Jupe",
|
10 => "Jupe",
|
||||||
"Veste",
|
"Veste",
|
||||||
"Blouson"
|
"Blouson"
|
||||||
];
|
];
|
||||||
$array = ["a","b","c"];
|
$array = ["a","b","c"];
|
||||||
$array[] = "d";
|
$array[] = "d";
|
||||||
@@ -23,4 +25,27 @@ 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,38 +1,55 @@
|
|||||||
<?php
|
<?php
|
||||||
include './include/data.inc.php';
|
include_once './include/data.inc.php';
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>tp1 - ex3</title>
|
<title>tp1 - ex3</title>
|
||||||
<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"
|
||||||
>
|
>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<h2>Exercice 3 : IMC </h2>
|
<h2>Exercice 3 : IMC </h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Nom</th>
|
<th>Nom</th>
|
||||||
<th>Prénom</th>
|
<th>Prénom</th>
|
||||||
<th>Email</th>
|
<th>Email</th>
|
||||||
<th>Taille</th>
|
<th>Taille</th>
|
||||||
<th>Poids</th>
|
<th>Poids</th>
|
||||||
<th>IMC</th>
|
<th>IMC</th>
|
||||||
</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;
|
||||||
|
|
||||||
<!-- À compléter -->
|
$imc = null;
|
||||||
|
if ($tailleM > 0) {
|
||||||
</tbody>
|
$imc = $poids / ($tailleM * $tailleM);
|
||||||
</table>
|
}
|
||||||
</main>
|
?>
|
||||||
</body>
|
<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>
|
||||||
|
</table>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,3 +1,19 @@
|
|||||||
|
<?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>
|
||||||
@@ -13,12 +29,12 @@
|
|||||||
</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/dice-six-faces-five.svg'>
|
<img src="./img/<?= $diceImages[$die1] ?>" alt="Dé 1 : <?= $die1 ?>">
|
||||||
<img src='./img/dice-six-faces-one.svg'>
|
<img src="./img/<?= $diceImages[$die2] ?>" alt="Dé 2 : <?= $die2 ?>">
|
||||||
</article>
|
</article>
|
||||||
<h5>Somme = </h5>
|
<h5>Somme = <?= $sum ?></h5>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
include './include/favoris.inc.php';
|
include_once './include/favoris.inc.php';
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
function createPassword($n,$alphabet){
|
function createPassword($n,$alphabet) {
|
||||||
$length = strlen($alphabet);
|
$length = strlen($alphabet);
|
||||||
$password = "";
|
$password = "";
|
||||||
return $password;
|
return $password;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
include './include/fonction.php';
|
include_once './include/fonction.php';
|
||||||
$alphabet = "@#!*^&azertyuiopqsdfghjkklmwxcvbnAZERTYUIOPLMKJHGFDSQWXCVBN1234567890";
|
$alphabet = "@#!*^&azertyuiopqsdfghjkklmwxcvbnAZERTYUIOPLMKJHGFDSQWXCVBN1234567890";
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|||||||
@@ -1,26 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
include 'include/controller.php';
|
include_once 'include/controller.php';
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
|
||||||
<head>
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
<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"
|
||||||
/>
|
/>
|
||||||
<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></title>
|
<title>Exercice 1</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<ul>
|
<ul>
|
||||||
<?php
|
<?php
|
||||||
echo "<li>$prenom $nom</li>";
|
echo '<li>' . htmlspecialchars($prenom . ' ' . $nom, ENT_QUOTES, 'UTF-8') . '</li>';
|
||||||
echo "<li><i class='fa-brands $icon fa-2x'></i></li>";
|
echo '<li>' . htmlspecialchars($systeme, ENT_QUOTES, 'UTF-8') . " <i class='fa-brands $icon fa-2x'></i></li>";
|
||||||
?>
|
?>
|
||||||
</ul>
|
</ul>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,2 +1,27 @@
|
|||||||
<?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,2 +1,18 @@
|
|||||||
<?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,23 +1,47 @@
|
|||||||
<?php
|
<?php
|
||||||
include 'include/controller.php';
|
include_once 'include/controller.php';
|
||||||
?>
|
?>
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<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"
|
||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
</head>
|
<title>Exercice 2</title>
|
||||||
<body>
|
</head>
|
||||||
<main>
|
<body>
|
||||||
<h4>Table de multiplication</h4>
|
<main>
|
||||||
<form method="GET">
|
<h4>Table de multiplication</h4>
|
||||||
<input type=number name="table" placeholder="table">
|
<form method="GET">
|
||||||
<button type="submit">ENVOYER</button>
|
<input
|
||||||
</form>
|
type="number"
|
||||||
</main>
|
name="table"
|
||||||
</body>
|
placeholder="table"
|
||||||
|
value="<?php echo htmlspecialchars($table, ENT_QUOTES, 'UTF-8'); ?>"
|
||||||
|
>
|
||||||
|
<button type="submit">ENVOYER</button>
|
||||||
|
</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>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,34 +1,59 @@
|
|||||||
<?php
|
<?php
|
||||||
include 'include/controller.php';
|
include_once 'include/controller.php';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title></title>
|
<title>Exercice 3</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.min.css"
|
||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main class="container">
|
<main class="container">
|
||||||
<h3>Calculatrice</h3>
|
<h3>Calculatrice</h3>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<input placeholder="un nombre" type="number" step="any" name="op1" value ="" required>
|
<input
|
||||||
<select name="operation" required>
|
placeholder="un nombre"
|
||||||
<option value="+">+</option>
|
type="number"
|
||||||
<option value="-">-</option>
|
step="any"
|
||||||
<option value="x">x</option>
|
name="op1"
|
||||||
<option value="/">/</option>
|
value="<?php echo htmlspecialchars($valeurOp1, ENT_QUOTES, 'UTF-8'); ?>"
|
||||||
</select>
|
required
|
||||||
<input placeholder="un nombre" type="number" step="any" name="op2" required>
|
>
|
||||||
<button type="submit" name="soumis"> Calculer</button>
|
<select name="operation" required>
|
||||||
</grid>
|
<option value="+" <?php echo $operation === '+' ? 'selected' : ''; ?>>+</option>
|
||||||
</form>
|
<option value="-" <?php echo $operation === '-' ? 'selected' : ''; ?>>-</option>
|
||||||
</main>
|
<option value="x" <?php echo $operation === 'x' ? 'selected' : ''; ?>>x</option>
|
||||||
</body>
|
<option value="/" <?php echo $operation === '/' ? 'selected' : ''; ?>>/</option>
|
||||||
|
</select>
|
||||||
|
<input
|
||||||
|
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>
|
||||||
|
</div>
|
||||||
|
</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>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,2 +1,56 @@
|
|||||||
<?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,3 +2,13 @@ button{
|
|||||||
|
|
||||||
float:right;
|
float:right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bonne-reponse {
|
||||||
|
color: #1b7f3a;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mauvaise-reponse {
|
||||||
|
color: #c62828;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,17 +1,81 @@
|
|||||||
|
<?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="en">
|
<html lang="fr">
|
||||||
<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"
|
||||||
/>
|
/>
|
||||||
<title></title>
|
<meta charset="UTF-8" />
|
||||||
</head>
|
<title>Exercice 4</title>
|
||||||
<body>
|
</head>
|
||||||
<main>
|
<body>
|
||||||
<h4>Réponses</h4>
|
<main>
|
||||||
</div>
|
<h4>Resultat du quizz</h4>
|
||||||
</main>
|
<?php if ($message !== '') : ?>
|
||||||
</body>
|
<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>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,23 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
include 'include/controller.php';
|
include_once 'include/controller.php';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<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"
|
||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
|
<title>Exercice 5</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
<h3>Conjugaison</h3>
|
||||||
|
|
||||||
<title></title>
|
<?php if ($messageErreur !== '') : ?>
|
||||||
</head>
|
<p><?php echo htmlspecialchars($messageErreur, ENT_QUOTES, 'UTF-8'); ?></p>
|
||||||
<body>
|
<?php else : ?>
|
||||||
<main>
|
<p>
|
||||||
|
Verbe :
|
||||||
|
<?php echo htmlspecialchars($verbe, ENT_QUOTES, 'UTF-8'); ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
</main>
|
<?php foreach ($conjugaisons as $conjugaison) : ?>
|
||||||
</body>
|
<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>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,12 +1,64 @@
|
|||||||
<?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')
|
||||||
);
|
);
|
||||||
|
|
||||||
$pronoms=array("je","tu","il","nous","vous","ils");
|
$libellesTemps = array(
|
||||||
|
'present' => 'Present',
|
||||||
|
'futur' => 'Futur',
|
||||||
|
'imparfait' => 'Imparfait'
|
||||||
|
);
|
||||||
|
|
||||||
$verbe = filter_input(INPUT_POST,"verbe",FILTER_SANITIZE_STRING);
|
$pronoms = array('je', 'tu', 'il', 'nous', 'vous', 'ils');
|
||||||
$radical = substr($verbe,0,strlen($verbe)-2);
|
|
||||||
|
$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);
|
||||||
|
|
||||||
|
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.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
# TP 3 : Passage de paramètres à un script, PHP-MariaDB avec l'extension **mysqli**.
|
||||||
|
|
||||||
|
> Le style utilisé dans les sources est [picocss](https://picocss.com/).
|
||||||
|
|
||||||
|
### Ex1.
|
||||||
|
Le but est d'écrire un script php simulant le jeu de hasard pierre,
|
||||||
|
feuille ciseaux (encore appelé chifoumi).
|
||||||
|
<div align="center">
|
||||||
|
<img src="./img/chifoumi.png">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Le joueur joue en cliquant sur l'icone représentant le coup qu'il
|
||||||
|
a choisi. Celui-ci est un lien vers le même script, auquel est passé
|
||||||
|
en GET un paramètre représentant son choix. Par exemple :
|
||||||
|
|
||||||
|
```html
|
||||||
|
<a href="?choice=0"><img href="rock.png"></a>
|
||||||
|
<a href="?choice=1"><img href="paper.png"></a>
|
||||||
|
<a href="?choice=2"><img href="scissors.png"></a>
|
||||||
|
```
|
||||||
|
Le script récupère le coup du joueur, fait un tirage aléatoire, et
|
||||||
|
affiche les deux coups joués avec un message pour indiquer le
|
||||||
|
résultat de la partie.
|
||||||
|
|
||||||
|
Le code est organisé sommairement suivant le pattern `MVC`. Le script `index.php` fait office de contrôleur.
|
||||||
|
- il récupére le choix du joueur,
|
||||||
|
- il fait jouer l'ordinateur (tirage aléatoire),
|
||||||
|
- il calcule l'issue de la partie,
|
||||||
|
- il affiche (include) les différentes parties de la vue finale, avec les variables nécessaires.
|
||||||
|
|
||||||
|
Remarque : pour éviter un code trop verbeux au niveau des tests pour calculer le résultat d'une partie,
|
||||||
|
vous pouvez utiliser un tableau pour représenter les règles du jeu. Par exemple,
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
// 0 rock, 1 paper, 2 scissors
|
||||||
|
$rules = [ 0 => [ 0 => "Draw", 1 => "Loss", 2 => "Win"], ... ];
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ex2.
|
||||||
|
|
||||||
|
**Avant de commencer**
|
||||||
|
>- Vous diposez, sur le serveur mysql qui tourne sur la machine
|
||||||
|
> dwarves.iut-fbleau.fr, d'un compte identifié par votre login. Le mot de
|
||||||
|
> passe a été initailisé avec votre login. Pensez à le changer
|
||||||
|
> rapidement.
|
||||||
|
>- Vous disposez en lecture/écriture d'une seule base de données
|
||||||
|
> identifiée là encore par votre login.
|
||||||
|
>- Vous avez aussi accès à cette
|
||||||
|
> [url](https://dwarves.iut-fbleau.fr/phpmyadmin/) à une interface web
|
||||||
|
> (phpmyadmin) de gestion de votre base.
|
||||||
|
|
||||||
|
Pour travailler, importez dans votre base les tables et leurs contenus
|
||||||
|
|
||||||
|
```sql
|
||||||
|
Artiste (idArtiste,nom,prenom,anneeNaiss)
|
||||||
|
---------
|
||||||
|
Genre (code)
|
||||||
|
----
|
||||||
|
Pays (code,nom,langue)
|
||||||
|
----
|
||||||
|
Film (idFilm,titre,annee,#idMes,#genre,resume,#codePays,urlImage)
|
||||||
|
------
|
||||||
|
Role (#idFilm,#idActeur,nomRole)
|
||||||
|
------- -------- -------
|
||||||
|
```
|
||||||
|
|
||||||
|
qui se trouvent dans le fichier **cinema.sql**. Vous pouvez directement
|
||||||
|
l'importer à partir de phpmyadmin. Examinez les tables, leurs
|
||||||
|
structures et relations.
|
||||||
|
|
||||||
|
 Par pitié !
|
||||||
|
|
||||||
|
**Testez directement vos requêtes sql avec phpmyadmin (ou autre) avant
|
||||||
|
des les "intégrer" à php !**
|
||||||
|
|
||||||
|
|
||||||
|
1. Complétez le script **films.php** qui affiche la liste de tous les films
|
||||||
|
de votre base sous forme d'une table html, classée par titre, avec
|
||||||
|
l'année, le genre et le réalisateur.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
<details><summary>Conseils</summary>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
- le serveur tourne sur le serveur http, donc pour vous connecter,
|
||||||
|
utiliser `localhost` comme nom.
|
||||||
|
- Pour récuperer les informations demandées, pensez à faire une
|
||||||
|
jointure entre Film et Artiste.
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
2. Modifiez le script précédent afin de paginer l'affichage des films.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
<details><summary>Conseils</summary>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
- La clause `LIMIT` dans un SELECT permet de restreindre le nombre de
|
||||||
|
résultats de la requête.
|
||||||
|
|
||||||
|
- L'option `SQL_CALC_FOUND_ROWS` permet, en présence de la clause
|
||||||
|
LIMIT, de savoir combien de resultats auraient été selectionnée en
|
||||||
|
son absence.
|
||||||
|
|
||||||
|
Il faut utliser juste après la requête la fonction MySQL
|
||||||
|
`FOUND_ROWS()`.
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
3. Ajoutez dans le script précédent un formulaire avec une liste déroulante
|
||||||
|
qui permet de filtrer les films par réalisateur.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
<details><summary>Conseils</summary>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
Il faut récupérer dans la table Artiste les réalisateurs, et peupler une
|
||||||
|
liste déroulante. La valeur envoyé par le formulaire sera bien sûr
|
||||||
|
l'identifiant du réalisateur.
|
||||||
|
|
||||||
|
Faites en sorte, comme sur la capture d'écran, de réafficher la liste
|
||||||
|
déroulante avec le nom du réalisateur dernièrement selectionné.
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
4. On veut dans cette question, à partir de la liste, afficher le détail
|
||||||
|
d'un film. Pour cela, chaque titre, dans le tableau, sera un lien qui
|
||||||
|
conduira à la fiche du film. L'identifiant du film sera passé dans
|
||||||
|
l'url du lien.
|
||||||
|
|
||||||
|
<a href="./fiche.php?film=1">Vertigo</a>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
5. Pour ceux qui s'ennuient, faites en sorte que l'on puisse trier
|
||||||
|
l'affichage sous forme de tableau par odre de titre, année, ou genre.
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
.center{
|
||||||
|
text-align:center;
|
||||||
|
}
|
||||||
|
.Win{
|
||||||
|
color:#2E8B57;
|
||||||
|
|
||||||
|
}
|
||||||
|
.Loss{
|
||||||
|
color:#FF6347;
|
||||||
|
}
|
||||||
|
.Draw{
|
||||||
|
color:#DAA520;
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
$ROCK = 0;
|
||||||
|
$PAPER = 1;
|
||||||
|
$SCISSORS = 2;
|
||||||
|
|
||||||
|
$images = ["rock.png", "paper.png", "scissors.png"];
|
||||||
|
$rules = [
|
||||||
|
$ROCK => [$ROCK => "Draw", $PAPER => "Loss", $SCISSORS => "Win"],
|
||||||
|
$PAPER => [$ROCK => "Win", $PAPER => "Draw", $SCISSORS => "Loss"],
|
||||||
|
$SCISSORS => [$ROCK => "Loss", $PAPER => "Win", $SCISSORS => "Draw"],
|
||||||
|
];
|
||||||
|
|
||||||
|
$playerChoice = filter_input(
|
||||||
|
INPUT_GET,
|
||||||
|
'choice',
|
||||||
|
FILTER_VALIDATE_INT,
|
||||||
|
['options' => ['min_range' => 0, 'max_range' => 2]]
|
||||||
|
);
|
||||||
|
|
||||||
|
$isPlaying = ($playerChoice !== null && $playerChoice !== false);
|
||||||
|
|
||||||
|
if ($isPlaying) {
|
||||||
|
$computerChoice = mt_rand(0, 2);
|
||||||
|
$message = $rules[$playerChoice][$computerChoice];
|
||||||
|
$class = $message;
|
||||||
|
$imagePlayer = $images[$playerChoice];
|
||||||
|
$imageComputer = $images[$computerChoice];
|
||||||
|
}
|
||||||
|
|
||||||
|
include_once './views/header.php';
|
||||||
|
if ($isPlaying) {
|
||||||
|
include_once './views/game.php';
|
||||||
|
include_once './views/message.php';
|
||||||
|
}
|
||||||
|
include_once './views/footer.php';
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<div class="grid">
|
||||||
|
<article>
|
||||||
|
<header>Player</header>
|
||||||
|
<section class="center">
|
||||||
|
<img src="./images/<?php echo $imagePlayer;?>">
|
||||||
|
</section>
|
||||||
|
</article>
|
||||||
|
<article>
|
||||||
|
<header>Computer</header>
|
||||||
|
<section class="center">
|
||||||
|
<img src="./images/<?php echo $imageComputer;?>">
|
||||||
|
</section>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" >
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
|
<title>Chifoumi</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
|
|
||||||
|
<h3>Rock Paper Scissors</h3>
|
||||||
|
|
||||||
|
<section class="center">
|
||||||
|
<p>Choose : </p>
|
||||||
|
<a href="?choice=0"><img width="100px" src="./images/rock.png"></a>
|
||||||
|
<a href="?choice=1"><img width="100px" src="./images/paper.png"></a>
|
||||||
|
<a href="?choice=2"><img width="100px" src="./images/scissors.png"></a>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<h2 class="center">
|
||||||
|
<span class="<?php echo $class;?>"><?php echo $message;?></span>
|
||||||
|
</h2>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
table{
|
||||||
|
width:100%;
|
||||||
|
}
|
||||||
|
img{
|
||||||
|
width:500px;
|
||||||
|
}
|
||||||
|
td + td + td + td{
|
||||||
|
width : 20%;
|
||||||
|
}
|
||||||
|
td:first-child + td{
|
||||||
|
width:10%;
|
||||||
|
}
|
||||||
|
td:first-child{
|
||||||
|
width:30%;
|
||||||
|
}
|
||||||
|
td:first-child + td + td {
|
||||||
|
width:30%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
include_once './modeles/modeleFilms.php';
|
||||||
|
|
||||||
|
$currentPage = filter_input(
|
||||||
|
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
|
||||||
|
//
|
||||||
|
|
||||||
|
include_once './vues/header.php';
|
||||||
|
include_once './vues/vueFilms.php';
|
||||||
|
include_once './vues/footer.php';
|
||||||
|
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
function getConnection()
|
||||||
|
{
|
||||||
|
static $conn = null;
|
||||||
|
|
||||||
|
if ($conn === null) {
|
||||||
|
$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();
|
||||||
|
if ($conn === false) {
|
||||||
|
return [
|
||||||
|
'films' => [],
|
||||||
|
'total' => 0,
|
||||||
|
'error' => 'Connexion MySQL impossible.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$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);
|
||||||
|
if ($result === false) {
|
||||||
|
return [
|
||||||
|
'films' => [],
|
||||||
|
'total' => 0,
|
||||||
|
'error' => 'Exécution de la requête impossible.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$films = mysqli_fetch_all($result, MYSQLI_ASSOC);
|
||||||
|
|
||||||
|
$totalResult = mysqli_query($conn, 'SELECT FOUND_ROWS() AS total');
|
||||||
|
$totalRow = $totalResult ? mysqli_fetch_assoc($totalResult) : ['total' => 0];
|
||||||
|
$total = isset($totalRow['total']) ? (int) $totalRow['total'] : 0;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'films' => $films,
|
||||||
|
'total' => $total,
|
||||||
|
'error' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Films</title>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<!--
|
||||||
|
Variables de la vue
|
||||||
|
$films : les films de la page
|
||||||
|
-->
|
||||||
|
|
||||||
|
<h2>Films</h2>
|
||||||
|
<?php if (!empty($errorMessage)) { ?>
|
||||||
|
<article><?php echo htmlspecialchars($errorMessage, ENT_QUOTES, 'UTF-8'); ?></article>
|
||||||
|
<?php } ?>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Titre</th>
|
||||||
|
<th>Année</th>
|
||||||
|
<th>Genre</th>
|
||||||
|
<th>Réalisateur</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
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 "
|
||||||
|
<tr>
|
||||||
|
<td><a href='#'>{$titre}</a></td>
|
||||||
|
<td>{$annee}</td>
|
||||||
|
<td>{$genre}</td>
|
||||||
|
<td>{$realisateur}</td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</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 } ?>
|
||||||
|
|
||||||
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 91 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 543 KiB |
@@ -0,0 +1,76 @@
|
|||||||
|
|
||||||
|
# TP4 : Cookies et sessions en PHP.
|
||||||
|
|
||||||
|
### Ex1.
|
||||||
|
Complétez le script `index.php` de l'exercice 1 de manière à
|
||||||
|
mémoriser grâce à un cookie votre os préféré (parmi Linux, Windows et
|
||||||
|
MacOS). Le cookie est valable pendant une minute, et l'os par
|
||||||
|
défaut est Linux.
|
||||||
|
|
||||||
|

|
||||||
|
### Ex2.
|
||||||
|
Le but est de créer un min-jeu de morpion.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Les variables de session :
|
||||||
|
- `grid` : le plateau du jeu. tableau de 9 cases, prennant les valeurs 0 (libre), 1 (joueur 1), 2 (joueur 2).
|
||||||
|
- `playerTurn` : le joueur qui joue.
|
||||||
|
|
||||||
|
Le script prend en paramètre la variable `pos` : la position du coup joué par le joueur.
|
||||||
|
|
||||||
|
### Ex3.
|
||||||
|
On désire rendre les pages du [tp3](./../tp3) (cinema) accessibles
|
||||||
|
uniquement à des utilisateur **inscrits au préalable**.
|
||||||
|
|
||||||
|
1. Rajouter à la base une table `user` qui comprend un **login**,
|
||||||
|
**email** et un **password**. (login est la clé)
|
||||||
|
2. Ecrire un formulaire d'inscription au site qui comprend les
|
||||||
|
champs correspondants. Vous enregistrerez dans la base la mot de
|
||||||
|
passe hashé avec la fonction
|
||||||
|
[password\_hash](http://php.net/manual/fr/function.password-hash.php)
|
||||||
|
de php.
|
||||||
|
3. Faire en sorte que toutes les pages de l'application soient
|
||||||
|
accessibles **uniquement** si l'utilisateur s'est authentifié.
|
||||||
|
(utiliser une session)
|
||||||
|
|
||||||
|
Ecrire les scripts ou pages suivants
|
||||||
|
<dl>
|
||||||
|
<dt><code>inscription.php</code></dt>
|
||||||
|
<dd>formulaire d'inscription, et qui traite les données du formulaire.
|
||||||
|
Si le formulaire n'est pas correctement rempli, Il est réaffiché.
|
||||||
|
(les champs correctes sont conservés !)</dd>
|
||||||
|
<dt><code>authentification.html</code></dt>
|
||||||
|
<dd>formulaire d'authentification.</dd>
|
||||||
|
<dt><code>verification.php</code></dt>
|
||||||
|
<dd>traite le formulaire précédent et vérifie si l'utilisateur est
|
||||||
|
enregistré. En cas de succés, renvoie vers la page d'accueil du
|
||||||
|
site. Pour éviter des attaques force brute, ajoutez une
|
||||||
|
temporisation qui ralentira de telles attaques.</dd>
|
||||||
|
<dt><code>securite.php</code></dt>
|
||||||
|
<dd>morceau de code que vous inclurez systématiquement dans vos pages
|
||||||
|
que vous voulez rendre accessible uniquement aux utilisateurs dûment
|
||||||
|
authentifiés. Ce script vérifiera l'existence d'une variable de
|
||||||
|
session créée lors de la connexion.</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
Pour permettre l'authentification d'un utilisateur, il faut que
|
||||||
|
login et le mot de passe conviennent. On compare le hash de
|
||||||
|
l'utilisateur stocké dans la base avec le hashage calculé du
|
||||||
|
password soumis lors de l'authentification :
|
||||||
|
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
// Voir l'exemple fourni sur la page de la fonction password_hash()
|
||||||
|
// pour savoir d'où cela provient.
|
||||||
|
$hash = '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq';
|
||||||
|
|
||||||
|
if (password_verify('rasmuslerdorf', $hash)) {
|
||||||
|
echo 'Le mot de passe est valide !';
|
||||||
|
} else {
|
||||||
|
echo 'Le mot de passe est invalide.';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
```
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
$osSet = ['linux','apple','windows'];
|
||||||
|
$os = "linux";
|
||||||
|
|
||||||
|
include './views/main.php';
|
||||||
|
?>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
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">
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
|
<form method="POST">
|
||||||
|
<fieldset class="grid">
|
||||||
|
<legend>Changez votre os</legend>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="os" value="linux">
|
||||||
|
<i class="fa fa-linux fa-2x" aria-hidden="true"></i>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="os" value="windows">
|
||||||
|
<i class="fa fa-windows fa-2x" aria-hidden="true"></i>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="os" value="apple">
|
||||||
|
<i class="fa fa-apple fa-2x" aria-hidden="true"></i>
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<button type="submit">Envoyer</button>
|
||||||
|
</form>
|
||||||
|
<article>
|
||||||
|
<header>Votre os</header>
|
||||||
|
<?php echo "<i class='fa fa-$os fa-5x'></i>";?>
|
||||||
|
<footer>
|
||||||
|
Rafraîchir la page <a href=""><i class="fa fa-refresh" aria-hidden="true"></i></a>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||