I am attempting to store an object into $_SESSION but I am having a few issues doing so.
Here is the class:
class Profile { var $username; var $password; var $admin; function __construct($username, $password) { $this->username = $username; $this->password = $password; } function getName() { return $this->username; } function isAdmin() { return $this->admin; } function setAdmin($admin) { return $this->admin = $admin; } } and I am storing the data inside the session this way:
$_SESSION['profile'] = serialize($profile); and when I attempt to load that data in another class I receive an error:
Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Profile" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in C:\wamp64\www\login\hidden.php on line 33
I have dumped the loaded object to check if it is actually being loaded and it appears the object has been unserialized and I can see all the data itself inside the object.
$profile = unserialize($_SESSION['profile']); var_dump($profile); and I receive this on my localhost when dumping it:
C:\wamp64\www\login\hidden.php:31: object(__PHP_Incomplete_Class)[1] public '__PHP_Incomplete_Class_Name' => string 'Profile' (length=7) public 'username' => string 'myles' (length=5) public 'password' => string 'myles' (length=5) public 'admin' => boolean true I am truly lost and have no idea what to do if someone could help me, that would be great.
$profile = new Profile("u", "p");That is, make sure you have included all the files that define that class.Profileclass in a separate file and include it in all the pages where you will be using itinclude "Profile.php"oops!