Bonjour,

Je ne sais pas si je suis au bon endroit quoi qu'il en soit voici mon problème.
J'ai 2 pages PHP (L.php et P.php).

L : Login
P : Page privée

Si je résume lorsque l'on clique sur la page L et on rentre le bon code: on accède à la page P(Privée).

Par contre si des petits malins veulent accéder à la page P sans le mot de passe normalement ils ne peuvent puisque il y a la protection if (!isset ($_SESSION['code'])), cependant mon code ne fonctionne pas.

Voici les codes respectifs de L et P

Code L:


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
<?php
session_start();
if(isset($_POST['bouton']))
{
	if($_POST['code']=='123')
		{
 
		$_SESSION['code']='123';
 
		header("Location:PP.php");
		}
	else
		{
		$erreur="code incorrect";
		}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>
 
<body>
<?php
//affichage d'un tableau
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>
<?php
if(isset($erreur)) echo "<h2>VOTRE CODE EST INCORRECT</h2>";
?>
 
<form id="monform" name="form1" method="post" action="L.php">
  <p>
    <label>Code :
      <input type="text" name="code"  />
    </label>
  </p>
 
  <p>
    <label>
      <input type="submit" name="bouton"  value="Envoyer" />
    </label>
  </p>
</form>
</body>
</html>
Code P:
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
 
<?php
session_start();
 
if (!isset ($_SESSION['code']))
{
	//print_r ($_SESSION);
	header("Location:L.php");
 
	}
?>
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
</head>
 
<body>
<h1>PAGE PRIVEE</h1>
 
</body>
</html>
Par avance merci pour votre aide,

Sitejmr,