Anzeo Posted October 10, 2009 Share Posted October 10, 2009 Hi, I'm currently working on some small websites and I'm forcing myself to write as much OO as possible. However I've been chewing on this problem for quite some time, therefore I'll share it with you: I've wrote a singleton class which acts as a session manager (responsible for validating login/logout/user data). The problem however is: I need this class to be persistent,like you'd used to have $_SESSION['username'], but then something like $_SESSION['manager'] where the last would store an object. I know persistent objects aren't possible (or at least not in an easy way), but does anyone know a simple and good solution for this? (I'd like to keep the class implementation as it is). I've understood serialization could do the trick, but this will store a file on the server with the user his/her login data. I believe this is a potential security risk? Any help greatly appreciated, Anzeo Link to comment https://forums.phpfreaks.com/topic/177194-solved-need-help-with-my-persistent-singleton-implementation/ Share on other sites More sharing options...
Anzeo Posted October 10, 2009 Author Share Posted October 10, 2009 Nevermind, found a way around. Can't believe it's THAT simple :/ It actually was my first idea but when at first it didn't seem to work I didn't dug deeper... -__-0 The solution is almost too easy: Store your class in a session variable, then just write a function equal to unserialize ('cause of the singleton design you cannot use unserialize directly). Sorry to bother you! Link to comment https://forums.phpfreaks.com/topic/177194-solved-need-help-with-my-persistent-singleton-implementation/#findComment-934291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.