This commit is contained in:
Mael G. 2023-03-22 00:13:04 -07:00
parent 90f8d78bf7
commit f76f0d19ff
37 changed files with 1077 additions and 0 deletions

27
td1_2/10.php Normal file
View file

@ -0,0 +1,27 @@
<?php
$tableau = array(
"nom" => "nunes",
"prenom" => "Jean-Claude",
"age" => 18,
"addresse" => "35400 Saint-Malo",
"profession" => "Java",
);
echo "<hr><h1>FOR :</h1>";
for ($i = 0; $i < count($tableau); $i++) {
print(array_keys($tableau)[$i] . ": ");
echo $tableau[array_keys($tableau)[$i]] . "<br/>";
}
echo "<hr><h1>PRINT_R :</h1>";
print_r($tableau);
echo "<hr><h1>FOREACH :</h1>";
foreach ($tableau as $key => $value) {
echo "$key: $value<br/>";
}

39
td1_2/11.php Normal file
View file

@ -0,0 +1,39 @@
<?php
$tableau = array(
"jean" => 14,
"claude" => 13,
"david" => 18,
"maxime" => 1,
);
$moyenne = 0;
foreach ($tableau as $prenom => $note) {
echo "$prenom: $note<br/>";
$moyenne += $note;
}
$moyenne = $moyenne / count($tableau);
echo "<p><strong>Moyenne :</strong> $moyenne";
// Modification des notes
foreach ($tableau as $prenom => $note) {
if ($prenom == "jean") {
continue;
}
$tableau[$prenom] = $note - 2;
}
echo "<hr><h3>Nouvelles notes</h3>";
?>
<pre>
<?php
print_r($tableau);
?>
</pre>

21
td1_2/2.php Normal file
View file

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<body>
<?php
echo "<h1>Bonjour à tous</h1>";
echo "<p>Salut <a href='lien'>lien</a></p>";
?>
</body>
</html>
<!--
Code source :
<!DOCTYPE html>
<html>
<body>
<h1>Bonjour à tous</h1><p>Salut <a href='lien'>lien</a></p>
</body>
</html>
-->

14
td1_2/3.php Normal file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<body>
<?php
$var = "a";
$var2 = 23;
echo $var;
echo "<br/>";
echo $var2;
echo $var." : bonjour !";
?>
</body>
</html>

9
td1_2/4.php Normal file
View file

@ -0,0 +1,9 @@
<?php
$var_a = 10;
$var_b = 20;
echo $var_a * $var_b . "<br/>";
echo $var_b + $var_a . "<br/>";

10
td1_2/5.php Normal file
View file

@ -0,0 +1,10 @@
<?php
$prenom = "Jean";
$nom = "Claude";
$addr = "18 Rue des écoles";
$age = 48;
echo "<p>Prenom : $prenom - Nom : $nom - Addresse : $addr - Age : $age</p><br/>";
echo ($age / 10) % 10;
?>

3
td1_2/6.php Normal file
View file

@ -0,0 +1,3 @@
<?php
echo($_SERVER["REMOTE_ADDR"]);

11
td1_2/7.php Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<body>
<pre>
<?php $var = "a";
$var2 = 23;
print_r($var . "<br/>");
print_r($var2); ?>
</pre>
</body>
</html>

13
td1_2/8.php Normal file
View file

@ -0,0 +1,13 @@
<?php
$prenom = "Jean";
$nom = "Petit";
$age = 5;
echo "<p>Prénom : $prenom<br/>Nom : $nom</p>";
if ($age < 18) {
echo "$prenom est mineur(e).";
} else {
echo "$prenom est majeur(e).";
}

24
td1_2/9.php Normal file
View file

@ -0,0 +1,24 @@
<?php
for ($i = 2004; $i <= 2022; $i++) {
echo "$i<br/>";
}
echo "<br/><br/>";
$k = 2004;
while ($k <= 2022) {
echo "$k<br/>";
$k++;
}
$k = 2004;
echo "<br/><br/>";
do {
echo "$k<br/>";
$k++;
} while ($k <= 2022);

48
td4/exo1.php Normal file
View file

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1> Formulaire </h1>
<form action="exo1_traitement.php" method="POST">
<label for="nom">Nom :</label>
<input type="text" id="nom" name="nom"><br><br>
<label for="email">Email :</label>
<input type="text" id="email" name="email"><br><br>
<label for="message">Message :</label>
<textarea id="message" name="message"></textarea><br><br>
<label>Choix unique :</label><br>
<input type="radio" id="choix1" name="choix" value="choix1">
<label for="choix1">Choix 1</label><br>
<input type="radio" id="choix2" name="choix" value="choix2">
<label for="choix2">Choix 2</label><br><br>
<label>Choix multiples :</label><br>
<input type="checkbox" id="option1" name="options[]" value="option1">
<label for="option1">Option 1</label><br>
<input type="checkbox" id="option2" name="options[]" value="option2">
<label for="option2">Option 2</label><br>
<input type="checkbox" id="option3" name="options[]" value="option3">
<label for="option3">Option 3</label><br><br>
<input name="userIP" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" type="hidden">
<input name="userDATE" value="<?php echo date("Y-m-d H:i:s"); ?>" type="hidden">
<input type="submit" value="Envoyer">
</form>
</body>
</html>

11
td4/exo1_traitement.php Normal file
View file

@ -0,0 +1,11 @@
<?php
foreach ($_POST as $cle => $valeur) {
if (is_string($valeur)) {
$valeur = strtolower($valeur);
}
if (is_array($valeur)) {
$valeur = implode(", ", $valeur);
}
echo "<strong>$cle</strong> : $valeur <br>";
}

92
td4/exo3.php Normal file
View file

@ -0,0 +1,92 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<div class="container p-5">
<h1> Formulaire </h1>
<form class="pt-3" method="POST" action="#">
<div class="mb-3">
<label for="nom" class="form-label">Nom :</label>
<input type="text" class="form-control" id="nom" name="nom">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email :</label>
<input type="text" class="form-control" id="email" name="email">
</div>
<div class="mb-3">
<label for="message" class="form-label">Message :</label>
<textarea class="form-control" id="message" name="message"></textarea>
</div>
<div class="mb-3">
<label class="form-label">Choix unique :</label><br>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" id="choix1" name="choix" value="choix1">
<label class="form-check-label" for="choix1">Choix 1</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" id="choix2" name="choix" value="choix2">
<label class="form-check-label" for="choix2">Choix 2</label>
</div>
</div>
<div class="mb-3">
<label class="form-label">Choix multiples :</label><br>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="option1" name="options[]" value="option1">
<label class="form-check-label" for="option1">Option 1</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="option2" name="options[]" value="option2">
<label class="form-check-label" for="option2">Option 2</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="option3" name="options[]" value="option3">
<label class="form-check-label" for="option3">Option 3</label>
</div>
</div>
<input name="userIP" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" type="hidden">
<input name="userDATE" value="<?php echo date("Y-m-d H:i:s"); ?>" type="hidden">
<button type="submit" name="valide" class="btn btn-primary">Envoyer</button>
</form>
<?php
if (isset($_POST['valide'])) {
echo "<h1> Réponse </h1>";
foreach ($_POST as $cle => $valeur) {
if (is_string($valeur)) {
$valeur = strtolower($valeur);
}
if (is_array($valeur)) {
$valeur = implode(", ", $valeur);
}
echo "<strong>$cle</strong> : $valeur <br>";
}
}
?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>

94
td4/exo4.php Normal file
View file

@ -0,0 +1,94 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<div class="container p-5">
<h1> Formulaire </h1>
<form class="pt-3" method="POST" action="#">
<div class="mb-3">
<label for="nom" class="form-label">Nom :</label>
<input type="text" class="form-control" id="nom" name="nom">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email :</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="mb-3">
<label for="url" class="form-label">URL :</label>
<input type="text" class="form-control" id="url" name="url">
</div>
<div class="mb-3">
<label for="message" class="form-label">Message :</label>
<textarea class="form-control" id="message" name="message"></textarea>
</div>
<div class="mb-3">
<label class="form-label">Choix unique :</label><br>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" id="choix1" name="choix" value="choix1">
<label class="form-check-label" for="choix1">Choix 1</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" id="choix2" name="choix" value="choix2">
<label class="form-check-label" for="choix2">Choix 2</label>
</div>
</div>
<div class="mb-3">
<label class="form-label">Choix multiples :</label><br>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="option1" name="options[]" value="option1">
<label class="form-check-label" for="option1">Option 1</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="option2" name="options[]" value="option2">
<label class="form-check-label" for="option2">Option 2</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="option3" name="options[]" value="option3">
<label class="form-check-label" for="option3">Option 3</label>
</div>
</div>
<input name="userIP" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" type="hidden">
<input name="userDATE" value="<?php echo date("Y-m-d H:i:s"); ?>" type="hidden">
<button type="submit" class="btn btn-primary">Envoyer</button>
</form>
<?php
if (isset($_POST['nom'])) {
echo "<h1> Réponse </h1>";
$mail = filter_var($_POST['email'], FILTER_SANITIZE_SPECIAL_CHARS);
$nom = filter_var($_POST['nom'], FILTER_SANITIZE_SPECIAL_CHARS);
$url = filter_var($_POST['url'], FILTER_SANITIZE_SPECIAL_CHARS);
echo "<p><strong>Nom : $nom</strong></p>";
echo "<p><strong>Email : $mail est <b>" . (filter_var($address, FILTER_VALIDATE_EMAIL) ? 'OK' : 'NOK') . " valide</b></p>";
echo "<p><strong>URL : $url est <b>" . (filter_var($url, FILTER_VALIDATE_URL) ? 'OK' : 'NOK') . " valide</b></p>";
}
?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>

3
td4/td4b/data1.txt Normal file
View file

@ -0,0 +1,3 @@
Jean Dupont jean.dupont@outlook.com
Pierre Martin p.mart1@gmail.com
Paul Durand durandpaul@caramail.fr

3
td4/td4b/data1_old.txt Executable file
View file

@ -0,0 +1,3 @@
Jean-Marc Pierrot jm.pierrot@univ-rennes.fr 019435812
Frederic Sanchez fredsanch@gmail.fr 0968134529
Stephanie Garcia setphanieg@outlook.com 0638913307

2
td4/td4b/data2.csv Normal file
View file

@ -0,0 +1,2 @@
David,Gatel,david@univ.fr,https://getbootstrap.com,192.168.64.1,"2023-03-16 01:29:20",csv,
fzani,fjia,jfai@euN.fr,http://a.fr,192.168.64.1,"2023-03-16 01:31:21",csv,
1 David Gatel david@univ.fr https://getbootstrap.com 192.168.64.1 2023-03-16 01:29:20 csv
2 fzani fjia jfai@euN.fr http://a.fr 192.168.64.1 2023-03-16 01:31:21 csv

22
td4/td4b/data2.json Executable file
View file

@ -0,0 +1,22 @@
[
{
"prenom": "af",
"nom": "afzaf",
"email": "ae@e.fr",
"url": "http:\/\/fazfzafza.fr",
"userIP": "192.168.64.1",
"userDATE": "2023-03-16 01:32:23",
"sortie": "json",
"valide": ""
},
{
"prenom": "af",
"nom": "afzaf",
"email": "ae@e.fr",
"url": "http:\/\/fazfzafza.fr",
"userIP": "192.168.64.1",
"userDATE": "2023-03-16 01:32:23",
"sortie": "json",
"valide": ""
}
]

1
td4/td4b/data2.txt Normal file
View file

@ -0,0 +1 @@
Jean Claude jean.claude@nunes.fr https://jean.fr 192.168.64.1 2023-03-16 00:50:15

56
td4/td4b/exo1.php Executable file
View file

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<?php
// Ouvre le fichier menu.txt en mode lecture
$menu_file = fopen("menu.txt", "r") or die("Impossible d'ouvrir le fichier menu.txt");
// Lit les lignes du fichier une à une
$menu_items = array();
while (!feof($menu_file)) {
$line = fgets($menu_file);
if ($line) {
// Sépare la ligne en deux parties : le titre et l'URL
$parts = explode(" ", $line);
$title = $parts[0];
$url = $parts[1];
// Ajoute un élément au tableau de menu
$menu_items[] = array("title" => $title, "url" => $url);
}
}
// Ferme le fichier
fclose($menu_file);
// Affiche la barre de menu
echo "<nav class='navbar navbar-expand-lg navbar-light bg-light'>";
echo "<div class='container-fluid'>";
echo "<a class='navbar-brand' href='#'>Menu</a>";
echo "<button class='navbar-toggler' type='button' data-bs-toggle='collapse' data-bs-target='#navbarNav' aria-controls='navbarNav' aria-expanded='false' aria-label='Toggle navigation'>";
echo "<span class='navbar-toggler-icon'></span>";
echo "</button>";
echo "<div class='collapse navbar-collapse' id='navbarNav'>";
echo "<ul class='navbar-nav'>";
foreach ($menu_items as $item) {
echo "<li class='nav-item'>";
echo "<a class='nav-link' href='" . $item["url"] . "'>" . $item["title"] . "</a>";
echo "</li>";
}
echo "</ul>";
echo "</div>";
echo "</div>";
echo "</nav>";
?>
</body>
</html>

32
td4/td4b/exo2.php Executable file
View file

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<div class="container mt-4">
<?php
$lines = file("data1.txt");
foreach ($lines as $line) {
$line = trim($line);
$parts = explode(" ", $line);
$prenom = $parts[0];
$nom = $parts[1];
$email = $parts[2];
$tel = $parts[3];
echo "<h1>$prenom $nom</h1><p>Email : <a href='mailto:$email'>$email</a><br/>Tél : $tel</p>";
}
?>
</div>
</body>
</html>

22
td4/td4b/exo3.php Executable file
View file

@ -0,0 +1,22 @@
<?php
$donnees = array(
"Jean" => array(
"nom" => "Dupont",
"email" => "jean.dupont@outlook.com"
),
"Pierre" => array(
"nom" => "Martin",
"email" => "p.mart1@gmail.com"
),
"Paul" => array(
"nom" => "Durand",
"email" => "durandpaul@caramail.fr"
),
);
foreach ($donnees as $prenom => $info) {
$data = $prenom . " " . $info["nom"] . " " . $info["email"];
file_put_contents("data1.txt", $data . PHP_EOL, FILE_APPEND);
echo "Ecriture de $prenom dans le fichier data1.txt<br/>";
}

94
td4/td4b/exo4.php Executable file
View file

@ -0,0 +1,94 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<div class="container p-5">
<h1> Formulaire </h1>
<form class="pt-3" method="POST" action="#">
<div class="mb-3">
<label for="prenom" class="form-label">Prenom :</label>
<input type="text" class="form-control" id="prenom" name="prenom">
</div>
<div class="mb-3">
<label for="nom" class="form-label">Nom :</label>
<input type="text" class="form-control" id="nom" name="nom">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email :</label>
<input type="text" class="form-control" id="email" name="email">
</div>
<div class="mb-3">
<label for="url" class="form-label">URL :</label>
<input type="url" class="form-control" id="url" name="url">
</div>
<input name="userIP" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" type="hidden">
<input name="userDATE" value="<?php echo date("Y-m-d H:i:s"); ?>" type="hidden">
<div class="mb-3">
<label class="form-label">Type de sortie :</label><br>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" id="choix1" name="sortie" value="txt">
<label class="form-check-label" for="choix1">Fichier texte</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" id="choix2" name="sortie" value="csv">
<label class="form-check-label" for="choix2">CSV</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" id="choix3" name="sortie" value="json">
<label class="form-check-label" for="choix3">JSON</label>
</div>
</div>
<button type="submit" name="valide" class="btn btn-primary">Envoyer</button>
</form>
<?php
if (isset($_POST['valide'])) {
echo "<h1> Réponse </h1>";
foreach ($_POST as $cle => $valeur) {
echo "<strong>$cle</strong> : $valeur <br>";
}
if ($_POST["sortie"] == "txt") {
file_put_contents("data2.txt", $_POST['prenom'] . " " . $_POST['nom'] . " " . $_POST['email'] . " " . $_POST['url'] . " " . $_POST['userIP'] . " " . $_POST['userDATE'] . "\n", FILE_APPEND);
} else if ($_POST["sortie"] == "csv") {
$fp = fopen('data2.csv', 'a');
fputcsv($fp, $_POST);
} else if ($_POST["sortie"] == "json") {
$actuel = file_get_contents('data2.json');
$listeTemp = json_decode($actuel);
if (is_array($listeTemp)) {
array_push($listeTemp, $_POST);
} else {
$listeTemp = array($_POST);
}
$donneesJson = json_encode($listeTemp);
file_put_contents('data2.json', $donneesJson);
}
}
?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>

5
td4/td4b/menu.txt Executable file
View file

@ -0,0 +1,5 @@
Exercice1 page01.php
Exercice2 page02.php
Exercice3 page03.php
Exercice4 page04.php
Exercice5 page05.php

24
td5/action/new.php Normal file
View file

@ -0,0 +1,24 @@
<?php
session_start();
if ($_SESSION["user"]["role"] != "admin") {
header("Location: index.php");
}
if (isset($_POST["valide"])) {
$newperso = array(
"name" => $_POST["nom"],
"birthDate" => $_POST["bdate"],
"deathDate" => $_POST["ddate"],
"image" => $_POST["imgurl"],
"description" => $_POST["description"]
);
$actuel = file_get_contents('../personnages.json');
$listeTemp = json_decode($actuel, true);
print_r($listeTemp["historicalFigures"]);
array_push($listeTemp["historicalFigures"], $newperso);
$donneesJson = json_encode($listeTemp);
file_put_contents('../personnages.json', $donneesJson);
header("Location: ../persos.php");
}

91
td5/connexion.php Normal file
View file

@ -0,0 +1,91 @@
<?php
session_start();
if (isset($_SESSION["user"])) {
header("Location: index.php");
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mon Site - Connexion</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<style>
html,
body {
height: 100%;
}
body {
display: flex;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
.form-signin {
max-width: 330px;
padding: 15px;
}
.form-signin .form-floating:focus-within {
z-index: 2;
}
.form-signin input[type="email"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
</style>
<!-- Custom styles for this template -->
<link href="sign-in.css" rel="stylesheet">
</head>
<body class="text-center">
<main class="form-signin w-100 m-auto">
<form method="POST" action="connexion_traitement.php">
<img class="mb-4" src="/docs/5.3/assets/brand/bootstrap-logo.svg" alt="" width="72" height="57">
<h1 class="h3 mb-3 fw-normal">Connectez-Vous</h1>
<?php
if (isset($_GET["error"])) {
echo "<div class='alert alert-danger' role='alert'>
Identifiant ou mot de passe incorrect
</div>";
}
?>
<div class="form-floating">
<input type="text" class="form-control" id="floatingInput" placeholder="john" name="identifiant">
<label for="floatingInput">Identifiant</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" id="floatingPassword" placeholder="Mot de passe" name="password">
<label for="floatingPassword">Mot de passe</label>
</div>
<input type="text" value="valider" name="valide" hidden>
<button class="w-100 btn btn-lg btn-primary" type="submit">Connexion</button>
<p class="mt-5 mb-3 text-muted">&copy; 2023</p>
</form>
</main>
</body>
</html>

View file

@ -0,0 +1,21 @@
<?php
if (isset($_POST["valide"])) {
$identifiant = $_POST["identifiant"];
$password = $_POST["password"];
$users = json_decode(file_get_contents("users.json"), true);
$user = null;
foreach ($users as $u) {
if ($u["username"] == $identifiant && $u["password"] == $password) {
$user = $u;
break;
}
}
if ($user == null) {
header("Location: connexion.php?error=1");
} else {
session_start();
$_SESSION["user"] = $user;
header("Location: index.php");
}
}

6
td5/deconnexion.php Normal file
View file

@ -0,0 +1,6 @@
<?php
session_start();
session_destroy();
header("Location: index.php?deconnexion=1");

57
td5/index.php Normal file
View file

@ -0,0 +1,57 @@
<?php
session_start();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Monsite</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Mon Site</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Accueil</a>
</li>
<li class="nav-item">
<a class="nav-link" href="persos.php">Personnages Historiques</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container m-5">
<?php if (isset($_GET["deconnexion"])) {
echo "<div class='alert alert-success' role='alert'>Vous êtes déconnecté.</div>";
}
?>
<div class="bg-light p-5 rounded">
<?php if (isset($_SESSION["user"])) { ?>
<h1>Bonjour <?= $_SESSION["user"]["username"] ?></h1>
<p class="lead">Vous êtes <strong class="text-danger"><?= $_SESSION["user"]["role"] ?></strong></p>
<a class="btn btn-lg btn-danger" href="deconnexion.php" role="button">Deconnexion &raquo;</a>
<?php } else { ?>
<h1>Vous n'êtes pas connecté.</h1>
<a class="btn btn-lg btn-primary" href="connexion.php" role="button">Connectez vous &raquo;</a>
<?php } ?>
</div>
</div>
<script src="/docs/5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>

1
td5/personnages.json Executable file
View file

@ -0,0 +1 @@
{"historicalFigures":[{"name":"Leonardo da Vinci","birthDate":"April 15, 1452","deathDate":"May 2, 1519","description":"Leonardo da Vinci was a Renaissance artist and inventor, best known for works like the Mona Lisa and The Last Supper. He was also a scientist and engineer, and made significant contributions to fields like anatomy and architecture.","image":"https:\/\/uploads0.wikiart.org\/images\/leonardo-da-vinci.jpg!Portrait.jpg"},{"name":"Cleopatra","birthDate":"69 BC","deathDate":"August 10, 30 BC","description":"Cleopatra was the last active pharaoh of ancient Egypt, and is famous for her relationships with Julius Caesar and Mark Antony. She was also a powerful political figure in her own right, and played a significant role in the power struggles of the Roman Republic.","image":"https:\/\/media.vogue.fr\/photos\/5c769fa2488cdc91cadf65f6\/2:3\/w_2560%2Cc_limit\/GettyImages-139633685.jpg"},{"name":"Nelson Mandela","birthDate":"July 18, 1918","deathDate":"December 5, 2013","description":"Nelson Mandela was a South African anti-apartheid revolutionary and politician, who served as the President of South Africa from 1994 to 1999. He was a prominent leader in the struggle against apartheid, and was imprisoned for 27 years before being released in 1990.","image":"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/0\/02\/Nelson_Mandela_1994.jpg\/640px-Nelson_Mandela_1994.jpg"},{"name":"Marie Curie","birthDate":"November 7, 1867","deathDate":"July 4, 1934","description":"Marie Curie was a Polish-born physicist and chemist, who conducted pioneering research on radioactivity. She was the first woman to win a Nobel Prize, and the first person to win two Nobel Prizes in different fields (physics and chemistry).","image":"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/7\/7e\/Marie_Curie_c1920.jpg\/1200px-Marie_Curie_c1920.jpg"},{"name":"William Shakespeare","birthDate":"April 26, 1564","deathDate":"April 23, 1616","description":"William Shakespeare was an English playwright and poet, widely regarded as one of the greatest writers in the English language. He wrote over 30 plays, including classics like Romeo and Juliet, Hamlet, and Macbeth.","image":"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/a\/a2\/Shakespeare.jpg\/800px-Shakespeare.jpg"},{"name":"ZBAD","birthDate":"13","deathDate":"1555","image":"https:\/\/google.com","description":"zffaaza"}]}

114
td5/persos.php Normal file
View file

@ -0,0 +1,114 @@
<?php
session_start();
if ($_SESSION["user"] == null) {
header("Location: connexion.php");
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Monsite</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Mon Site</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.php">Accueil</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="persos.php">Personnages Historiques</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container p-5">
<div class="row g-5">
<?php
if ($_SESSION["user"]["role"] == "admin") {
?>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#nouveauPerso" data-bs-whatever="@new">Nouveau personnage</button>
<?php
}
$personnages = json_decode(file_get_contents("personnages.json"), true);
foreach ($personnages["historicalFigures"] as $perso) {
?>
<div class="col col-3">
<div class="card">
<img src="<?= $perso["image"] ?>" class="card-img-top" alt="Photo de <?= $perso["name"] ?>">
<div class="card-body">
<h5 class="card-title"><?= $perso["name"] ?></h5>
<p class="text-muted"><?= $perso["birthDate"] ?> - <?= $perso["deathDate"] ?></p>
<p class="card-text"><?= $perso["description"] ?></p>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<div class="modal fade" id="nouveauPerso" tabindex="-1" aria-labelledby="nouveauPersoLabel" aria-hidden="true">
<div class="modal-dialog">
<form method="POST" action="action/new.php">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="nouveauPersoLabel">Nouveau personnage historique
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="col-form-label">Nom :</label>
<input type="text" class="form-control" name="nom" required>
</div>
<div class="mb-3">
<label class="col-form-label">Lien vers l'image :</label>
<input type="url" class="form-control" name="imgurl" required>
</div>
<div class="mb-3">
<label class="col-form-label">Date de naissance :</label>
<input type="text" class="form-control" name="bdate" required>
</div>
<div class="mb-3">
<label class="col-form-label">Date de décès :</label>
<input type="text" class="form-control" name="ddate" required>
</div>
<div class="mb-3">
<label class="col-form-label">Description :</label>
<textarea class="form-control" name="description" required></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
<input type="submit" class="btn btn-primary" value="Ajouter">
</div>
</div>
<input type="text" value="valider" name="valide" hidden>
</form>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>

14
td5/users.json Normal file
View file

@ -0,0 +1,14 @@
[
{
"username": "mgramain",
"password": "bonjour",
"email": "maelgramain@etudiant.univ-rennes1.fr",
"role": "admin"
},
{
"username": "john35",
"password": "R139OO",
"email": "john35@gmail.com",
"role": "user"
}
]

42
td5/users.php Normal file
View file

@ -0,0 +1,42 @@
<?php
$users = json_decode(file_get_contents("users.json"), true);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Utilisateurs</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body class="container">
<h1 class="mt-5">Liste d'utilisateurs</h1>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Username</th>
<th scope="col">Password</th>
<th scope="col">E-Mail</th>
<th scope="col">Role</th>
</tr>
</thead>
<tbody>
<?php
foreach ($users as $user) {
echo "<tr>";
echo "<td>" . $user['username'] . "</td>";
echo "<td>" . $user['password'] . "</td>";
echo "<td>" . $user['email'] . "</td>";
echo "<td>" . $user['role'] . "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</body>
</html>

39
tdajax/index.php Normal file
View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>JSON Content</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
setInterval(function() {
$.ajax({
url: "showDate.php",
dataType: "json",
success: function(data) {
$("#json-content").text(JSON.stringify(data));
}
});
}, 1);
});
$(document).ready(function() {
$("#myInput").on("input", function() {
$.ajax({
url: "write.php",
method: "POST",
data: {
content: $(this).val()
}
});
});
});
</script>
</head>
<body>
<div id="json-content"></div>
<input type="text" id="myInput">
</body>
</html>

8
tdajax/showDate.php Normal file
View file

@ -0,0 +1,8 @@
<?php
$res = array(
"date" => date('d-m-y h:i:s')
);
header("Content-Type: application/json");
echo (json_encode($res));

1
tdajax/texte.txt Executable file
View file

@ -0,0 +1 @@
zaddzadza

3
tdajax/write.php Normal file
View file

@ -0,0 +1,3 @@
<?php
file_put_contents("texte.txt", $_POST);