Skip to content

Instantly share code, notes, and snippets.

@azihassan
Created May 4, 2015 10:14
Show Gist options
  • Save azihassan/d68ecb2ba57cc7cb3e11 to your computer and use it in GitHub Desktop.
Save azihassan/d68ecb2ba57cc7cb3e11 to your computer and use it in GitHub Desktop.
SQLi demonstration.
<?php
session_start();
$conn = mysqli_connect('localhost', 'root', '', 'test');
if(mysqli_connect_error())
{
echo '<p>Connexion à la base de données échouée : ' . mysqli_connect_error() . '</p>';
exit;
}
?>
<form method = "post">
<label><p>Login : <input type = "text" name = "login" /></p></label>
<label><p>Mot de passe : <input type = "password" name = "mdp" /></p></label>
<input type = "submit" value = "Connexion" />
</form>
<?php
if(isset($_POST['login'], $_POST['mdp']))
{
$login = $_POST['login'];
$mdp = $_POST['mdp'];
$sql = "SELECT * FROM utilisateurs WHERE login = '$login' AND mdp = '$mdp'";
echo "<p>Requête SQL : $sql</p>";
$req = mysqli_query($conn, $sql);
if($req === false)
die('<p>Erreur MySQL : ' . mysqli_error($conn) . '</p>');
if(mysqli_num_rows($req) == 0)
die('<p>Login ou mot de passe incorrect.</p>');
echo '<p>Login et mot de passe corrects.</p>';
$_SESSION['login'] = $login;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment