16 Mai
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								BACKEND/PHP/tp3.tar.gz
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								BACKEND/PHP/tp3.tar.gz
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										11
									
								
								BACKEND/PHP/tp3/chifoumi/css/style.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								BACKEND/PHP/tp3/chifoumi/css/style.css
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| .center{ | ||||
| 	text-align:center; | ||||
| } | ||||
| .gagne{ | ||||
| color:#2E8B57; | ||||
|  | ||||
| } | ||||
| .perdu{ | ||||
|  | ||||
| color:#FF6347; | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								BACKEND/PHP/tp3/chifoumi/images/ciseaux.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								BACKEND/PHP/tp3/chifoumi/images/ciseaux.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 16 KiB | 
							
								
								
									
										
											BIN
										
									
								
								BACKEND/PHP/tp3/chifoumi/images/feuille.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								BACKEND/PHP/tp3/chifoumi/images/feuille.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 17 KiB | 
							
								
								
									
										
											BIN
										
									
								
								BACKEND/PHP/tp3/chifoumi/images/pierre.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								BACKEND/PHP/tp3/chifoumi/images/pierre.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 13 KiB | 
							
								
								
									
										7
									
								
								BACKEND/PHP/tp3/chifoumi/include/jeu.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								BACKEND/PHP/tp3/chifoumi/include/jeu.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| <?php | ||||
| $vue=FALSE; | ||||
| $images=["pierre.png","feuille.png","ciseaux.png"]; | ||||
|  | ||||
| // TODO | ||||
|  | ||||
| ?> | ||||
							
								
								
									
										52
									
								
								BACKEND/PHP/tp3/chifoumi/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								BACKEND/PHP/tp3/chifoumi/index.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| <?php | ||||
| include 'include/jeu.php'; | ||||
|  | ||||
| // variable de la vue definies par le controleur | ||||
| // $coup_[joueur|oridnateur] | ||||
| // $image_[joueur|ordinateur] | ||||
| // $message  | ||||
| // $vue booleen pour affichage si un coup a été joué | ||||
| // | ||||
| ?> | ||||
| <!DOCTYPE html> | ||||
| <html lang="fr"> | ||||
| 	<head> | ||||
| 		<meta charset="UTF-8" > | ||||
|  | ||||
| 		<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@1.*/css/pico.min.css"> | ||||
| 		<link rel="stylesheet" href="./css/style.css"> | ||||
| 		<title>Chifoumi</title> | ||||
| 	</head> | ||||
| 	<body> | ||||
| 		<main class="container"> | ||||
| 			<h3>Pierre, Feuille, Ciseaux</h3> | ||||
| 			<div class="center"> | ||||
| 				<p>Choississez votre coup </p> | ||||
| 				<a href="?coup=0"><img width="50px" src="./images/pierre.png"></a> | ||||
| 				<a href="?coup=1"><img width="50px" src="./images/feuille.png"></a> | ||||
| 				<a href="?coup=2"><img width="50px" src="./images/ciseaux.png"></a> | ||||
| 			</div> | ||||
|  | ||||
| 			<?php if ($vue): ?> | ||||
| 			<div class="grid"> | ||||
| 				<article> | ||||
| 					<h5 ">Votre Coup</h5> | ||||
| 					<hr> | ||||
| 					<div class="center"> | ||||
| 						<img src="./images/<?php echo $image_joueur;?>"> | ||||
| 					</div> | ||||
| 				</article> | ||||
| 				<article> | ||||
| 					<h5>Celui de l'ordinateur</h5> | ||||
| 					<hr> | ||||
| 					<div class="center"> | ||||
| 						<img src="./images/<?php echo $image_ordinateur;?>"> | ||||
| 					</div> | ||||
| 				</article> | ||||
| 			</div> | ||||
| 			<h2 class="center"><span class="<?php echo $class;?>"><?php echo $message;?></span></h2> | ||||
| 			</div> | ||||
| 			<?php endif; ?> | ||||
| 		</main> | ||||
| 	</body> | ||||
| </html> | ||||
							
								
								
									
										
											BIN
										
									
								
								BACKEND/PHP/tp4.tar.gz
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								BACKEND/PHP/tp4.tar.gz
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										73
									
								
								BACKEND/PHP/tp4/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								BACKEND/PHP/tp4/README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,73 @@ | ||||
|  | ||||
| #  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 son 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.'; | ||||
| } | ||||
| ?> | ||||
| ``` | ||||
|  | ||||
							
								
								
									
										12
									
								
								BACKEND/PHP/tp4/ex1/css/style.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								BACKEND/PHP/tp4/ex1/css/style.css
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| main>section { | ||||
| display: flex;  | ||||
|  align-items:center; | ||||
|  justify-content:space-between; | ||||
| } | ||||
|  | ||||
| section > section { | ||||
| width: 25%;  | ||||
| } | ||||
| section > section + section { | ||||
| width: 50%; | ||||
| } | ||||
							
								
								
									
										58
									
								
								BACKEND/PHP/tp4/ex1/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								BACKEND/PHP/tp4/ex1/index.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| <?php | ||||
| $OS = "linux"; | ||||
| if(!isset($_POST['OS'])){ | ||||
| 	if (!isset($_COOKIE['OS'])){ | ||||
| 		setcookie('OS', $OS, time()+60); | ||||
| 	} else { | ||||
| 		$OS = $_COOKIE['OS']; | ||||
| 	} | ||||
| } else { | ||||
| 	$OS=$_POST['OS']; | ||||
| 	setcookie('OS', $OS, time()+60); | ||||
| } | ||||
| ?> | ||||
| <!doctype html> | ||||
| <html> | ||||
| 	<head> | ||||
| 		<meta charset="UTF-8"> | ||||
|  | ||||
| 		<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@1.*/css/pico.min.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"> | ||||
|  | ||||
| 	</head> | ||||
| 	<body> | ||||
| 		<main class="container"> | ||||
| 			<section> | ||||
| 				<section> | ||||
| 					<form method="POST"> | ||||
| 						<fieldset> | ||||
| 							<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> | ||||
| 				</section> | ||||
| 				<section> | ||||
| 					<p> | ||||
| 						<?php echo "<i class='fa fa-$OS fa-4x'></i>";?> | ||||
| 					</p> | ||||
| 					<p>Rafraîchir la page <a href=""><i class="fa fa-refresh" aria-hidden="true"></i></a></p> | ||||
| 				</section> | ||||
| 			</section> | ||||
| 		</main> | ||||
| 	</body> | ||||
| </html> | ||||
|  | ||||
							
								
								
									
										32
									
								
								BACKEND/PHP/tp4/ex2/css/style.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								BACKEND/PHP/tp4/ex2/css/style.css
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| table.morpion{ | ||||
| 	border-collapse: collapse; | ||||
| 	table-layout:fixed; | ||||
| 	margin-left:auto; | ||||
| 	margin-right:auto; | ||||
| 	display:inline-block; | ||||
| 	width:auto; | ||||
| } | ||||
| table.morpion td { | ||||
| 	border : 1px solid #aaaaaa; | ||||
| 	width:10rem; | ||||
| 	height:10rem; | ||||
| 	padding : 0px; | ||||
| 	margin:0px; | ||||
| 	overflow: hidden; | ||||
| 	white-space: nowrap; | ||||
| 	text-align:center; | ||||
| 	vertical-align:middle; | ||||
| } | ||||
| table.morpion i { | ||||
| font-size:8rem; | ||||
| } | ||||
|  | ||||
| table.morpion a { | ||||
| display : inline-block; | ||||
| width : 8rem; | ||||
| height: 8rem; | ||||
|  | ||||
| } | ||||
| .center{ | ||||
| 	text-align:center; | ||||
| } | ||||
							
								
								
									
										66
									
								
								BACKEND/PHP/tp4/ex2/include/tictactoe.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								BACKEND/PHP/tp4/ex2/include/tictactoe.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| <?php | ||||
| $message = ""; | ||||
| $grid = [0,1,0,1,0,2,2,0,0]; | ||||
|  | ||||
|  | ||||
| // | ||||
| // TODO | ||||
| // | ||||
| // | ||||
|  | ||||
| function isWinner($grid, $player) | ||||
| { | ||||
| 	$winStates = array | ||||
| 		( | ||||
| 			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),     // Vertical | ||||
| 			array(0, 4, 8), array(2, 4, 6)                      // Diagonal | ||||
| 		); | ||||
|  | ||||
| 	foreach ($winStates as $winState) | ||||
| 	{ | ||||
| 		if ($grid[$winState[0]] == $player && | ||||
| 			$grid[$winState[1]] == $player && | ||||
| 			$grid[$winState[2]] == $player) | ||||
| 		{ | ||||
| 			return true; | ||||
| 		} | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
|  | ||||
| function noWinner($grid) | ||||
| { | ||||
| 	for($i = 0; $i < 9; $i++) | ||||
| 		if ($grid[$i] == 0)  | ||||
| 			return false; | ||||
|  | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| function displayGrid($grid) | ||||
| { | ||||
| 	echo '<table class="morpion">'; | ||||
| 	for ($i = 0; $i < 3; $i ++){ | ||||
| 		echo "<tr>"; | ||||
| 		for ($j = 0; $j < 3; $j ++){ | ||||
|  | ||||
| 			echo "<td>"; | ||||
|  | ||||
| 			$pos = 3*$i + $j; | ||||
| 			if ($grid[$pos] == 0) | ||||
| 				echo "<a href='?pos=$pos'></a>"; | ||||
| 			if ($grid[$pos] == 1) | ||||
| 				echo '<i class="fa fa-times" aria-hidden="true"></i>'; | ||||
| 			if ($grid[$pos] == 2) | ||||
| 				echo '<i class="fa fa-circle-o" aria-hidden="true"></i>'; | ||||
|  | ||||
| 			echo "</td>"; | ||||
|  | ||||
| 		} | ||||
|  | ||||
| 		echo "</tr>"; | ||||
| 	} | ||||
|  | ||||
| 	echo "</table>"; | ||||
| } | ||||
							
								
								
									
										26
									
								
								BACKEND/PHP/tp4/ex2/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								BACKEND/PHP/tp4/ex2/index.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| <?php | ||||
| include 'include/tictactoe.php'; | ||||
| ?> | ||||
| <html> | ||||
| 	<head> | ||||
| 		<meta charset="UTF-8"> | ||||
| 		<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@1.*/css/pico.min.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"> | ||||
|  | ||||
| 	</head> | ||||
| 	<body> | ||||
| <main class="container center"> | ||||
| <h3>Tic Tac Toe : <?php echo "player $playerTurn turn";?></h3> | ||||
|  | ||||
| <?php | ||||
| if ($message != ""){ | ||||
| echo "<h1>$message"; | ||||
| echo "  <a  href='?'>new game</a></h1>"; | ||||
| } | ||||
| displayGrid($grid); | ||||
| ?> | ||||
| </main> | ||||
| </body> | ||||
| </html> | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								BACKEND/PHP/tp4/img/cookie.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								BACKEND/PHP/tp4/img/cookie.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 18 KiB | 
							
								
								
									
										
											BIN
										
									
								
								BACKEND/PHP/tp4/img/ttt.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								BACKEND/PHP/tp4/img/ttt.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 22 KiB | 
		Reference in New Issue
	
	Block a user