Jump to content

[SOLVED] Need help with my persistent singleton implementation


Anzeo

Recommended Posts

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

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.