salut je me suis stoppé comment s'identifier dans un formulaire d'administration d'un site pour y acceder des pages protégés .
je me suis servi des class bon voila exemple de mon code
index.php
class.identification.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 <?php include('class.Identification.php'); $connexion = new Identification(); $affichage = ''; if(!$connexion->connexion($_POST)){ $affichage = '<p class="error">MDP ou Login incorrects</p>'; } if(isset($_GET['deconnexion'])){ if($_GET['deconnexion'] == true){ $connexion->deconnexion(); } } ?> <html> <head> <title>Identification</title> </head> <body> <?=$affichage?> <form action="index.php" method="POST"> <label>Login</label><input type="text" name="login"/> <label>MDP</label><input type="password" name="mdp"/> <button type="submit">Valider</button> </form> </body> </html>
protege.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 <?php class Identification{ public function __construct() { session_start(); } public function connexion($tab){ if(!empty($tab['login'])){ $login = $tab['login']; $mdp = $tab['mdp']; include('config.php'); $connect = mysql_connect(MYHOST, MYUSER, MYPASS) or die ('Identifiants incorrects'); mysql_select_db(MYDB) or die ('Base de données incorrecte'); $requete = 'SELECT id,login,mdp FROM utilisateurs WHERE login="'.mysql_real_escape_string($login).'" AND mdp="'.mysql_real_escape_string(md5($mdp)).'"'; $result = mysql_query($requete); $utilisateur = mysql_fetch_assoc($result); if(mysql_num_rows($result) == 1){ $_SESSION['connecte'] = true; $_SESSION['id'] = $utilisateur['id']; header('Location:protege.php'); return true; } return false; mysql_close($connect); } else{ return true; } } public function deconnexion(){ session_destroy(); unset($_SESSION); } public function verificationAcces(){ if($_SESSION['connecte'] == true) header('Location:index.php'); } } ?>
bon quand j'execute d'apres le index.php il me donne erreur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 <?php include('class.Identification.php'); $identification = new Identification(); $identification->verificationAcces(); echo 'Ouaw! Des infos confidentielles <a href="index.php?deconnexion=true">Se déconnecter</a>'; ?>
c'est surParse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in c:\documents and settings\administrateur\bureau\protection-page\class.Identification.php on line 3public function __construct()
ca veux dire qu'il accepte pas ma fonction ou il y a une erreur en accolade ajouté
svp pouvez vous m'aidez sur ca ainsi je suis debutant en programmation objet en phpmerci







Répondre avec citation




Partager