Erreur Session objet non reconnue
Résolu
PlagLeFleau
Messages postés
8
Date d'inscription
Statut
Membre
Dernière intervention
-
PlagLeFleau Messages postés 8 Date d'inscription Statut Membre Dernière intervention -
PlagLeFleau Messages postés 8 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
J'ai un problème lorsque j'essaie de récupérer l'objet que j'ai dans enregistré dans la variable de session.
Voilà l'erreur :
Fatal error: Uncaught Error: The script tried to call a method on an incomplete object. Please ensure that the class definition "Connected" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide an autoloader to load the class definition in C:\xampp\htdocs\php\menu.php:28 Stack trace: #0 C:\xampp\htdocs\index.php(10): require_once() #1 {main} thrown in C:\xampp\htdocs\php\menu.php on line 28
Class connected:
Class GestionUtilisateur:
Class rang:
J'ai un problème lorsque j'essaie de récupérer l'objet que j'ai dans enregistré dans la variable de session.
Voilà l'erreur :
Fatal error: Uncaught Error: The script tried to call a method on an incomplete object. Please ensure that the class definition "Connected" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide an autoloader to load the class definition in C:\xampp\htdocs\php\menu.php:28 Stack trace: #0 C:\xampp\htdocs\index.php(10): require_once() #1 {main} thrown in C:\xampp\htdocs\php\menu.php on line 28
<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <link href="css/menu.css" rel="stylesheet" type="text/css"> <title>Acceuil</title> </head> <body class="body"> <table> <tr> <td> <a href="../index.php" class="menu"> <img src="../images/AcceuilButton.png" width="85" height="37"> </a> </td> <td> <a href="php/deconnexion.php"> <img src="../images/DeconnexionButton.png" width="85" height="37"> </a> </td> <?php include_once 'Class/Rang.class.php'; include_once 'Class/GestionUtilisateur.class.php'; require_once 'Class/Connected.class.php'; $gestion = new GestionUtilisateur(); if($_SESSION['connected'] != null) { $user = $_SESSION['connected']; if($user->getRank() === $gestion->getRanks()[0]->getRank()) { echo '<td><a href="list_user.php"><img src="../images/ListeUtilisateurButton.png" width="85" height="37"></a></td>'; } } ?> </tr> </table> </body> </html>
Class connected:
<?php class Connected { private string $username; private string $password; private string $rank; public function __construct(string $username, string $password, string $rank) { $this->setUsername($username); $this->setPassword($password); $this->setRank($rank); } public function getUsername() : string { return $this->username; } public function setUsername(string $username): void { $this->username = $username; } public function getPassword() : string { return $this->password; } public function setPassword(string $password): void { $this->password = $password; } public function getRank() : string { return $this->rank; } public function setRank(string $rank): void { $this->rank = $rank; } }
Class GestionUtilisateur:
<?php include_once "Utilisateur.class.php"; include_once 'Rang.class.php'; class GestionUtilisateur { private array $users = array(); private string $dsn = 'mysql:host=127.0.0.1;dbname=univers;port=3306;charset=utf8'; private array $ranks; public function __construct(){ try { $bdd = new PDO($this->dsn, 'root' , ''); } catch (PDOException $exception) { mail('VOTRE_EMAIL', 'PDOException', $exception->getMessage()); exit('Erreur de connexion à la base de données'); } $reponse = $bdd->query('SELECT * FROM user'); while ($donnees = $reponse->fetch()) { $this->addUser($donnees['username'],$donnees['password'], $donnees['rang'], $donnees['id']); } $reponse = $bdd->query('SELECT * FROM rank'); while ($donnees = $reponse->fetch()) { $this->ranks[] = new Rang($donnees['id_rank'], $donnees['rank']); } $reponse->closeCursor(); } public function addUser($username, $password, $rank, $id) { $this->users[] = new Utilisateur($username, $password, $rank, $id); } public function addNewUser($username, $password) { try { $bdd = new PDO($this->dsn, 'root' , ''); } catch (PDOException $exception) { mail('VOTRE_EMAIL', 'PDOException', $exception->getMessage()); exit('Erreur de connexion à la base de données'); } $sql = "INSERT INTO user(id, username, password, rang) VALUES (null,?,?,3)"; $stmt= $bdd->prepare($sql); $stmt->execute([$username, $password]); } public function readTab() : string{ $rang = null; $return = "<div class='centre'><table class='list'><tr><td class='listCell'>Ids</td><td class='listCell'>Usernames</td><td class='listCell'>Passwords</td><td>Ranks</td>"; for ($i = 0; $i < count($this->users); $i++) { for ($j = 0; $j < count($this->ranks); $j++) { if($this->users[$i]->getRank() == $this->ranks[$j]->getId()) { $rang = $this->ranks[$j]->getRank(); break; } } $return .= "<tr>"; $return .= "<td class='listCell'>".$this->users[$i]->getId()."</td>"; $return .= "<td class='listCell'>".$this->users[$i]->getUsername()."</td>"; $return .= "<td class='listCell'>".$this->users[$i]->getPassword()."</td>"; $return .= "<td class='listCell'>".$rang."</td>"; $return .= "</tr>"; } $return .= "</table></div>"; return $return; } public function getUserRank(int $rankID) : string { for ($i = 0; $i < count($this->ranks); $i++) { if($rankID == $this->ranks[$i]->getId()) { return $this->ranks[$i]->getRank(); } } return "null"; } public function getUsers(): array { return $this->users; } public function getRanks(): array { return $this->ranks; } }
Class rang:
<?php class rang { private int $id; private string $rank; public function __construct(int $id, string $rank) { $this->setId($id); $this->setRank($rank); } public function getId(): int { return $this->id; } public function setId(int $id): void { $this->id = $id; } public function getRank(): string { return $this->rank; } public function setRank(string $rank): void { $this->rank = $rank; } }
Configuration: Windows / Firefox 97.0
A voir également:
- Erreur Session objet non reconnue
- Cle usb non reconnue - Guide
- Vente objet occasion entre particulier - Guide
- Objet interdit en cabine ryanair - Guide
- Erreur t32 ✓ - Forum Livebox
- Erreur 0x80070643 - Accueil - Windows
1 réponse
yg_be
Messages postés
23541
Date d'inscription
Statut
Contributeur
Dernière intervention
Ambassadeur
1 584
bonjour,
peux-tu indiquer le nom du fichier pour chaque ficher que tu partages?
nous as-tu montré l'ensemble de ton code?
peux-tu indiquer le nom du fichier pour chaque ficher que tu partages?
nous as-tu montré l'ensemble de ton code?
quand tu partages le contenu d'un fichier, peux-tu veiller à préciser le nom du fichier?