1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| <?php
// ---------------------
// Initialisation des variables
$login = '';
$pass = '';
$validForm_lo = true;
$MsgErreur = '';
// ---------------------
// TRAITEMENT SI FORMULAIRE SOUMIS
if(isset($_POST['Form_id_Submit'], $_POST['antiF5'], $_SESSION['antiF5']) && $_POST['antiF5']==$_SESSION['antiF5'])
{
// ---------------------
// RECUPERATION des DONNEES
$login = (isset($_POST['login']))? htmlspecialchars(stripslashes(trim($_POST['login']))) : '';
$pass = (isset($_POST['pass']))? htmlspecialchars(stripslashes(trim($_POST['pass']))) : '';
// ---------------------
// CHAMPS OBLIGATOIRES
$champ_obligatoire = array();
$search = array (" ", "-", "'", "ğ", "Ğ", "ş", "Ş", "ı", "I", "Á", "À", "Â", "Ä", "Å", "Ã", "Ç", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ñ", "Ó", "Ò", "Ô", "Ö", "Õ", "Ø", "", "Ú", "Ù", "Û", "Ü", "Ý", "", "", "Ð", "Þ", "á", "à", "â", "ä", "å", "ã", "ç", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ñ", "ó", "ò", "ô", "ö", "õ", "ø", "", "ú", "ù", "û", "ü", "ý", "ÿ", "", "&", "ð", "þ", "ß", "æ", "", "Æ", "");
$replace = array ("", "", "", "t", "t", "t", "t", "t", "t", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a");
if ($login=='' || ctype_alnum(str_replace($search, $replace, $login))!=true || strlen($login)!=9) {$validForm_lo = false; $champ_obligatoire[] = 'login'; }
if ($pass=='' || ctype_alnum(str_replace($search, $replace, $pass))!=true || strlen($pass)!=8) {$validForm_lo = false; $champ_obligatoire[] = 'pass'; }
if(count($champ_obligatoire)>0)
{
$MsgErreur .= '*Champs obligatoires : '.implode(', ',$champ_obligatoire).'<br />';
echo "<script type='text/javascript'>alert(\"Veuillez renseigner tous les champs obligatoires!\")</script>";
}
// -----------------------
// OK SI PAS D'ERREUR
if($validForm_lo === true)
{
// ---------------------
if($login!='' && $pass!='')
{
// ---------------------
// Comparaison avec login et pass de la table
// connexion vers bdd mysql
try{
$chaine_connexion='mysql:host=localhost;dbname=cemkay';
$utilisation_UFT8=array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
$connexion_bdd = new PDO($chaine_connexion, 'root', '', $utilisation_UFT8);
$connexion_bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
$msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
die($msg);
}
//Preparer la requete
$sql = 'SELECT identifiant, mot_passe FROM connect WHERE identifiant =?';
$requete2 = $connexion_bdd ->prepare($sql);
//Associer des valeurs aux place holders
$requete2->bindValue(1, 'cemalkaya', PDO::PARAM_STR);
//Compiler et executer la requete
$requete2->execute();
//Recuperer toutes les donnees retournees
foreach($requete2->fetchAll() as $donnee)
{
$data_login=$donnee['identifiant'];
$data_mot_passe=$donnee['mot_passe'];
}
//Clore la requete preparee
$requete2 -> closeCursor();
$requete2 = NULL;
// si identifiant et mot de passe corrects
if ($data_login == $login && $data_mot_passe == $pass)
{
session_start();
$_SESSION['login'] = $_POST['login'];
header('Location: membre.php');
exit();
}
// si on ne trouve aucune réponse, le visiteur s'est trompé soit dans son login, soit dans son mot de passe
else
$MsgErreur = 'Compte non reconnu.';
}
}
}
?>
<?php
// ------------------------------------------
// anti-F5: eviter les post multiples suite à F5
unset($_POST); // unset: Détruit une variable
// anti-F5 (évite de re-poster le formulaire en cas de F5 ("Actualiser la page")
$_SESSION['antiF5'] = rand(100000,999999); // rand: Génère une valeur aléatoire
?>
<!DOCTYPE html> <!--on declare au validator le langage utilisé: html5-->
<html lang="fr">
<?php include("0-head.php"); ?>
<body>
<div class="container">
<?php include("0-menu.php"); ?>
<br>
<hr>
<form action="index.php" method='post'>
<table align="center" border="0">
<tr>
<td>
<input type="hidden" name="antiF5" value="<?php echo $_SESSION['antiF5']; ?>" />
</td>
</tr>
<tr>
<td>Login :</td>
<td><input type="text" name="login" maxlength="250"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" maxlength="10"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="Form_id_Submit" value="log in"></td>
</tr>
</table>
</form>
<?php if(!empty($MsgErreur)) { ?>
<p class="message_erreur_yellow"><?php echo $MsgErreur; ?></p>
<?php } ?>
<br>
<hr>
<?php include("0-pied-de-page.php"); ?>
</div>
</body>
</html> |
Partager