Bonjour,
j'ai un code qui génère des cookies si l'utilisateur coche la case "se souvenir de moi". Mon souci, c'est que si on coche cette case, on retrouve les cookies, même après avoir effacé l'historique.
Peut-on me dire ce qui ne va pas dans mon code ?
html2-milieu.php
Ce sont les cookies des lignes 15 et 19 qui restent tout le temps.
Code php : 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 if ( ! $_SESSION["auth"]) { ?> <main> <section> <form id="authform" action="<?php echo SITE_URL_HTTP;?>/page/authenticate.php" method="post"> <fieldset id="form-area1"> <p> <a href="http://www.schneider-electric.com/b2b/en/campaign/life-is-on/life-is-on.jsp" target="_blank"> <img src="<?php echo SITE_URL_HTTP; ?>/images/logo/LifeIsOn1x30_transparent.jpg" alt=''/></a><span class="dblock"></span> <?php echo $str[323]; ?> <h2><i class="fa fa-user-o" aria-hidden="true"></i> LOGIN</h2> <p> <label for="login2">Username</label> <input id="login2" type="text" size="30" value="<?php if (isset($_COOKIE['user'])) echo $_COOKIE['user'];else echo "";?>" name="login2" /> </p> <p> <label for="pwd2">Password</label> <input class="btsubmit" id="pwd2" type="text" size="30" value="<?php if (isset($_COOKIE['htoken'])) echo $_COOKIE['htoken'];else echo "";?>" name="pwd2" /> <input type="submit" value="Submit" name="goAuth" /> </p> </fieldset> <fieldset id="form-area2"> <p> <label for="remember"><?php echo $str[324]; ?></label> //la case "se souvenir de moi" <input type="checkbox" id="remember" name="remember" /> </p> </fieldset> </form> </section> <br /> </main>
authenticate.php
Code php : 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 function authentification() { global $bdd; $auth=false; //to check if login and pwd are present in the table user $sql = 'select * from `users`'; $qid = $bdd->prepare($sql); $qid->execute(); while ($row=$qid->fetch(PDO::FETCH_ASSOC) ) { $usr = $row['user']; $password = $row['password']; if (($usr == $_POST['login2']) && ($password == $_POST['pwd2'])) { $auth = true; $_SESSION['user']=$usr; } } if (!$auth) { //to check if login and token are present in the table authenticate $sql = 'select * from `authenticate`'; $qid = $bdd->prepare($sql); $qid->execute(); while ($row=$qid->fetch(PDO::FETCH_ASSOC) ) { $usr = $row['user']; $token = $row['password']; if (($usr == $_POST['login2']) && ($token == $_POST['pwd2'])) { $auth = true; $_SESSION['user']=$usr; } } if (isset($_POST['remember'])) { $_SESSION['remember']=true; require_once(dirname(__DIR__).'/page/remember.php'); } else {//to delete all cookies setcookie ("user","", time() + $temps); setcookie ("htoken","", time() + $temps); } } if (!$auth) { $_SESSION['remember']=false; } $_SESSION['auth']=$auth; return $auth; } $auth=authentification(); header ("Location: $_SERVER[HTTP_REFERER]" ); exit();
remember.php
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 //to generate a random value $token=rand(); $hash_token=md5($token); $temps = 365*24*3600; setcookie ("user",$_SESSION['user'], time() + $temps); setcookie ("htoken",$hash_token, time() + $temps);
Partager