I need to redesign the back-end of a website and need some help getting started. The original website uses OOP, there is a class "User" used to saved data when users log on. This is serialized and unserialized on each page as needed:
// login.php
$user = new User($iduser);
// ...
// At the end of the script
$_SESSION["user"] = serialize($user);
// Another page
$user = unserialize ($_SESSION["user"]);
Thus that data is available on every page that the user visits. Plus, in (almost) every page visited, $_SESSION["user"] is updated with new data (it’s quite possible that page_a.php doesn’t use data that page_b.php needs to show).
The new design should be fully object oriented. And the main problem I find is that I don’t know how to store properly that $_SESSION["user"] in a class method.
I tried to use Codeigniter, but it uses session variables with cookies, and that is not what I need.
Any suggestion or link would be helpful. Thanks in advance.
$_SESSION. Anyway, can't you write a class that wraps$_SESSION? The calls themselves won't be OOP, but you can hide all non-OOP calls (to other functions as well) in classes.$_SESSIONis a superglobal. So you can "write" to it wherever you want. It does not matter if that is within a class method or a function in the global namespace.