Clément Krebs 6 жил өмнө
parent
commit
a2f9e83877

+ 18 - 0
Tp2/authenticate.php

@@ -0,0 +1,18 @@
+<?php
+    session_start();
+    include_once('users.php');
+
+    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+        $login = htmlspecialchars($_POST['login']);
+        $passwd = htmlspecialchars($_POST['passwd']);
+        
+        if (array_key_exists($login, $users) && $passwd == $users[$login]) {
+            $_SESSION['login'] = $login;
+            header('Location: welcome.php');
+        } else {
+        $_SESSION['message'] = "Bad username or password";
+            header('Location: signin.php');
+        }
+    } else {
+        header('Location: signin.php');
+    }

+ 29 - 0
Tp2/signin.php

@@ -0,0 +1,29 @@
+<!doctype html>
+<html lang="fr">
+<head>
+  <meta charset="utf-8">
+  <title>Tp 1</title>
+  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
+  <link rel="stylesheet" type="text/css" href="style.css">
+</head>
+<body>
+
+    <p>Salut</p>
+    
+    <form action="authenticate.php" method="post">
+     login :<br>
+    <input type="text" name="login"><br>
+     password :<br>
+    <input type="password" name="passwd"><br>
+    <input type="submit" value="Log in">
+    </form>
+    <?php 
+        session_start();
+        if (isset($_SESSION['message'])) {
+            echo('<section> error : ' . $_SESSION['message'] . '</section>');
+            unset($_SESSION['message']);
+        }
+    ?>
+
+</body>
+</html>

+ 4 - 0
Tp2/signout.php

@@ -0,0 +1,4 @@
+<?php
+    session_start();
+    session_destroy();
+    header('Location: signin.php');

+ 3 - 0
Tp2/style.css

@@ -0,0 +1,3 @@
+input {
+    border-color: lightgreen;
+}

+ 4 - 0
Tp2/users.php

@@ -0,0 +1,4 @@
+<?php
+$users = [
+    "clem" => 'aze'
+];

+ 10 - 0
Tp2/welcome.php

@@ -0,0 +1,10 @@
+<?php
+    session_start();
+    if (isset($_SESSION['login'])) {
+        echo('Salut ' . $_SESSION['login']);
+        echo('<form action="signout.php" method="post">');
+        echo('<input type="submit" value="Sign out">');
+        echo('</form>');
+    } else {
+        header('Location: signin.php');
+    }