Connection identifiant + pass
Bonjour, voilà je réalise actuellement un script permettant de me connecté sur mon site a l'aide d'un identifiant et d'un pass avec une base de donnée derrière. C'est à dire que je voudrais que la connexion ne marche que si le login et le passe se trouve dans la base de donnée. En l'occurrence le code que j'ai fait comporte un problème puisqu'on peux ce connecté même avec un login et passé erroné et je ne trouve pas mon erreur.
Voila mon script, j'espère que vous pourrais m'aidé .
Code:
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
| <?php
// on teste si le visiteur a soumis le formulaire de connexion
if (isset($_POST['connexion']) == 'Connexion')
{
if ((isset($_POST['login']) && !empty($_POST['login'])) && (isset($_POST['password']) && !empty($_POST['password'])))
{
$base = mysql_connect ('localhost', 'root', '');
mysql_select_db ('ttom');
// on teste si une entrée de la base contient ce couple login / pass
$sql = 'SELECT login,password FROM membre WHERE login="'.mysql_escape_string($_POST['login']).'" AND password="'.mysql_escape_string($_POST['password']).'"';
$req = mysql_query($sql)
or exit('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$data = mysql_fetch_array($req);
mysql_close();
// si on obtient une réponse, alors l'utilisateur est un membre
if ($data[0] == 1)
{
session_start();
$_SESSION['login'] = $_POST['login'];
header('Location: index.php');
exit(mysqli_error());
echo "<script>alert('test reussi');</script>";
}
// si on ne trouve aucune réponse, le visiteur s'est trompé soit dans son login, soit dans son mot de passe
elseif ($data[0] == 1)
{
echo "<script>alert('Compte non reconnu');</script>";
}
// sinon, alors la, il y a un gros problème :)
else {
echo "<script>alert('Probème dans la base de données : plusieurs membres ont les mêmes identifiants de connexion');</script>";
}
}
else
{
echo "<script>alert('Au moins un des champs est vide.');</script>";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Ttom</title>
<link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
</head>
<body>
<div id="outer">
<div id="wrapper">
<div id="nav">
<div id="nav-left">
<div id="nav-right">
<ul>
<li><a href="http://www.freewebsitetemplates.com">ABOUT US</a></li>
<li><a href="http://www.freewebsitetemplates.com">PRODUCTS</a></li>
<li><a href="http://www.freewebsitetemplates.com">SERVICES</a></li>
<li><a href="http://www.freewebsitetemplates.com">SHOPPING CART</a></li>
<li><a href="http://www.freewebsitetemplates.com">NEW GADGETS</a></li>
</ul>
</div>
</div>
<div class="clear"></div>
</div>
<div id="head">
<div id="head-left"></div>
<div id="head-right"></div>
<div id="head-1"></div>
<img src="images/ttom1.jpg">
<div id="navb">
<ul>
<li><a href="http://www.freewebsitetemplates.com">HOME</a></li>
<li><a href="http://www.freewebsitetemplates.com">CONTACT</a></li>
</ul>
</div>
</div>
<div id="login">
<div id="login-bot">
<div id="login-box">
<h2 class="login"><em>user</em>login</h2>
<form action="ButFrance.php" method="post">
<div id="login-username">
<div><label for="username">login</label>: <input type="text" name="login" value="" id="username" /></div>
<div><label for="password">password</label>: <input type="password" name="password" value="" id="password" /></div>
</div>
<div id="login-button">
<input type="submit" value="Connexion" src="images/btn_login.gif"/>
</div>
</form>
</div>
<div id="login-welcome">
<div>
<h2><Center>Bienvenu</center></h2>
<p>Information : La case Username sur votre gauche attend une adresse mail.
</div>
</div>
<div class="clear"></div>
</div>
</div>
<div id="body">
<div id="body-bot">
<div id="footer">
<div id="footloose"><span class="logo"><span class="top">Ttom</span><span class="gadgets">Transport International</span></span></div>
<p>© Copyright 2010. All rights reserved.</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html> |
Et ici c'est la page que je veux voir après avoir entré le login et le pass !
Code:
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
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Ttom</title>
<link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
</head>
<body>
<div id="outer">
<div id="wrapper">
<div id="nav">
<div id="nav-left">
<div id="nav-right">
<ul>
<li><a href="http://localhost/Ttom/index.php">ABOUT US</a></li>
<li><a href="http://localhost/Ttom/index.php">PRODUCTS</a></li>
<li><a href="http://localhost/Ttom/index.php">SERVICES</a></li>
<li><a href="http://localhost/Ttom/index.php">SHOPPING CART</a></li>
<li><a href="http://localhost/Ttom/index.php">NEW GADGETS</a></li>
</ul>
</div>
</div>
<div class="clear"></div>
</div>
<div id="head">
<div id="head-left"></div>
<div id="head-right"></div>
<div id="head-1"></div>
<img src="images/ttom1.jpg">
<div id="navb">
<ul>
<li><a href="http://localhost/Ttom/index.php">HOME</a></li>
<li><a href="http://localhost/Ttom/index.php">CONTACT</a></li>
</ul>
</div>
</div>
<div id="body"><br>
<center><img src="images/cartewal.jpg"></center>
<div id="body-bot">
<div id="footer">
<div id="footloose"><span class="logo"><span class="top">Ttom</span><span class="gadgets">Transport International</span></span></div>
<p>© Copyright 2010. All rights reserved.</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html> |