🔒️ Sanitization of author name to prevent errors caused by quotes and double quotes

This commit is contained in:
Florian Sylvain
2021-10-31 00:17:31 +02:00
parent 3464719c02
commit 794f4094c9
2 changed files with 16 additions and 9 deletions
+1 -1
View File
@@ -8,6 +8,6 @@ class conf
private pdo $pdo; private pdo $pdo;
public function getPDO() : pdo { public function getPDO() : pdo {
return new PDO('mysql:host=localhost;dbname=' . getenv('DBNAME'), getenv('USERNAME'), getenv('PASSWORD')); return new PDO('mysql:host=localhost;charset=UTF8;dbname=' . getenv('DBNAME'), getenv('USERNAME'), getenv('PASSWORD'));
} }
} }
+15 -8
View File
@@ -5,20 +5,12 @@
<meta name="viewport" <meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="app.js"></script>
<link rel="stylesheet" href="stylesheet.css"> <link rel="stylesheet" href="stylesheet.css">
<title>Document</title> <title>Document</title>
</head> </head>
<body> <body>
<?php <?php
include("navbar.php"); include("navbar.php");
if (isset($_GET['author'])) {
if (strlen($_GET['author']) < 3) {
echo "<p class='error'>Veuillez entrer 3 caractères minimum.</p>";
} else {
echo "<script>requestToApi('" . $_GET['author'] . "')</script>";
}
}
?> ?>
<!-- La petite animation de chargement provient de : <!-- La petite animation de chargement provient de :
@@ -39,5 +31,20 @@
<div id="results-count"></div> <div id="results-count"></div>
<div id="results"></div> <div id="results"></div>
<script src="app.js"></script>
<?php
if (isset($_GET['author'])) {
if (strlen($_GET['author']) < 3) {
echo "<p class='error'>Veuillez entrer 3 caractères minimum.</p>";
} else {
echo "<script>requestToApi('" . filter_var($_GET['author'], FILTER_SANITIZE_ADD_SLASHES) . "')</script>";
}
} else {
echo "<script>document.getElementsByClassName('loader')[0].style.display = \"none\"</script>";
}
?>
</body> </body>
</html> </html>