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
|
<?php
// Connection DB
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mabase") or die(mysql_error());
// Vérifie si cookie
if(isset($_COOKIE['username']))
// Si cookies déja activé et log redirection direct.
{
$username = $_COOKIE['username'];
$pass = $_COOKIE['password'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{
header("Location: members.php");
}
}
}
//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
die('Champs incorecte.');
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
//Login existe pas
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('Cet utilisateur n\'existe pas. <a href=register.php>Cliquer ici pour vous enregistrez.</a>');
}
$_POST['pass'] = stripslashes($_POST['pass']);
$_POST['pass'] = md5($_POST['pass']);
while($info = mysql_fetch_array( $check ))
{
//Mot de passe incorecte
if ($_POST['pass'] != $info['password']){
die('Mot de pass incorect. Veuillez ressayer.');
}
else
{
// Si mot de passe correct
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
//Redirection parti membre
header("Location: members.php");
}
}
}
else
{
// Non enregistré
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h1>Login</h1></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="50">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>
<?php
}
?> |