- I have created a class named User and saved the file as User.inc
- Created a page page1.php where I'm instantiating an object, serializing the object, saving it to a session as $_SESSION['myUser']; and routing to a second page. Let's say page2.php.
- On page2.php, I unserialize the object saved in $_SESSION['myUser']; and print out their attributes and use some functions as well.
Everything works fine as expected; however when I hit the browser's "REFRESH", the structure breaks. Can't get any attributes and/or methods.
When I test to see if I have the serialized object in the session using isset($_SESSION['myUser']), I get true, but the structure of the object is gone.
At the beggining of each page I have done include(User.inc);
Any ideas.
// ****** User.inc *********
class User {
var $id;
// Constructor
function User() {
return true;
}
//******* page1.php *******
$userObj = new User();
$userObj->id = "1";
$_SESSION['myUser'] = serialize($userObj);
//****** page2.php *********
$userObj = unserialize($_SESSION['myUser']);
echo($userObj->id);
// *****************************
The first time I do get the output on page2.php
// refresh
Then everything is lost.
Please help 😕 :mad: