Created
March 29, 2022 16:31
-
-
Save LouisHrg/470a26f351ac604a98a5ec16a3f98749 to your computer and use it in GitHub Desktop.
Correction TP Injection SQL 3IW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once __DIR__ . "/vendor/autoload.php"; | |
| require_once __DIR__ . "/helpers/Mysql.php"; | |
| require_once __DIR__ . "/helpers/Tooling.php"; | |
| require_once __DIR__ . "/helpers/Views.php"; | |
| $app = new Leaf\App; | |
| $app->blade; | |
| $blade = new Leaf\Blade(); | |
| $blade->configure("views", "views/cache"); | |
| $app->get("/login", function() use($app, $blade) { | |
| echo $blade->make('login')->render(); | |
| }); | |
| $app->post("/login", function() use($app, $blade) { | |
| $email = $_POST['email'] ?? null; | |
| $password = $_POST['password'] ?? null; | |
| if($email && $password) | |
| { | |
| $mysql = new Mysql; | |
| // En tant normal sur PHP, utilisez PDO ! | |
| $sql = "SELECT id FROM users WHERE email = ?"; | |
| if ($stmt = mysqli_prepare($mysql->conn, $sql)) { | |
| // addslashes permet d'enlever les quotes d'une chaine de caractère | |
| mysqli_stmt_bind_param($stmt, "s", addslashes($email)); | |
| mysqli_stmt_execute($stmt); | |
| mysqli_stmt_bind_result($stmt, $userId); | |
| mysqli_stmt_fetch($stmt); | |
| // On a récupéré l'id de l'utilisateur de manière sécurisée | |
| // on peut faire d'autres traitements par la suite | |
| dd($userId); | |
| mysqli_stmt_close($stmt); | |
| } | |
| } | |
| return $app->response()->redirect("/login"); | |
| }); | |
| $app->get("/boot", function() use($app) { | |
| $mysql = new Mysql; | |
| $mysql->boot(); | |
| $app->response()->markup('Database crée avec succès'); | |
| }); | |
| $app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment