Hello,
Here's my system. Once a user is successfully logged in, a new instance of a User class is created. The constructor of this class grabs the details of the logged-in user from a database and stores them inside properties in the User class.
The problem is, obviously I'd want to access these properties from any page I require them to be able to display user data. But couldn't figure out the best way to do it.
I then fount out you could actually assign an object to a session. Which would be perfect for what I need.
When I tried implementing this, I ran into a bunch of errors and I couldn't figure it out.
Here's an example:
After a user has logged in, I have the following code:
$_SESSION['user'] = new User($this->username);
I was under the impression that this assigns a user object to a session. But it's not working as I receive this error:
Notice: Undefined index: user in ../v2/admin/index.php on line 18
Then on the page I want to display the name of the current user logged-in, I had this code:
$_SESSION['user']->get_Name();
But then I get this error:
Fatal error: Call to a member function get_IP() on a non-object in ../v2/admin/index.php on line 18
Can tell me what I have to do, to make this work?
Thanks.