Bonjour,
j ai une page de login me permet de m 'authentifier au niveau de la base tout est ok.
mon souci est que quand je met mon login et mon mot de passe il me renvoie vers la page de login "admin.php" donc que ca ne fonctionne pas j'ai testé la variable $username sur le deuxième fichier test.php la variable est vide j pense qu'il s'agit d'un probleme de cookie mais je ne vois pas ou merci de m'aider
page de login : admin.php
et le script2: test.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) { echo "<script language=\"JavaScript\">\n"; echo "window.location.href = 'admin3.php'"; echo "</script>"; } $check = mysql_query("SELECT * FROM matable WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo "<script language=\"JavaScript\">\n"; echo "window.location.href = 'admin2.php'"; echo "</script>"; } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { echo "<script language=\"JavaScript\">\n"; echo "window.location.href = 'admin4.php'"; echo "</script>"; } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area echo "<script language=\"JavaScript\">\n"; echo "window.location.href = 'test.php'"; echo "</script>"; } } } else { // if they are not logged in ?> <?php include("header2.php"); ?> <div id="page"> <div id="loginbox"> <h1>Se connecter</h1> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table style="padding-left: 20px;"> <tr> <td style="color:white;">Nom d'utilisateur:</td> <td style="height: 30px;" class="field"><input type="text" name="username" maxlength="40"></td> </tr> <tr> <td style="color:white;">Mot de passe:</td> <td style="height: 30px;" class="field"><input type="password" name="pass" maxlength="50"></td> </tr> <tr><td colspan="2" align="right"> <input style="margin-right: 65px; margin-top: 5px;" type="submit" name="submit" value="Connexion"> </td></tr> </table> </form> </div> </div> <?php ?> <?php include("footer2.php"); } ?>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM matable WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { header("Location: admin.php"); } else { include("header2.php"); ?> <div id="page"> <?php echo '<a href="import.php">Importer un fichier</a>'; echo '<a href="supprimer.php">Supprimer un fichier</a>'; ?> </div> <?php include("footer2.php"); } } } else { echo "<script language=\"JavaScript\">\n"; echo "alert('$username');"; echo "</script>"; } ?>
Partager