Page 1 of 1
Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 6:32 am
by szucskrysz
Hello guys,
I am new here and I am using PHP for a short time!
I would like to use the Singleton Pattern to store log in information about a user through several pages. Is that possible to get the stored information from the Singleton Class through several pages without using Session?
I hope my question is understandable.
Thanks
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 7:54 am
by jaoudestudios
Why must you use the singleton pattern?
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 8:00 am
by szucskrysz
I don't have to use Singleton I was just wondering if I can use it instead of putting log in information into session variables.
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 8:02 am
by jaoudestudios
The only way to transfer information between pages using php variables is to use sessions - that is what they are there for

Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 8:06 am
by szucskrysz
Thanks, I have already used sessions for that, but I thought there is an other cleaver way to do that, but it seems not!
Thanks again
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 8:08 am
by jaoudestudios
Not as far as I know.
Maybe someone else wants to shed some light on this.
But from my experience sessions are the way to go - fast & secure.
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 8:15 am
by szucskrysz
I have read somewhere that you should not store sensitive data in session because they can be manipulated!?
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 8:29 am
by Eran
Generally sessions are pretty secure as they are stored server-side and outside of the document root.
There are other alternatives for persistence - such as
memcached,
APC and database.
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 8:37 am
by jaoudestudios
Are they installed by default on php5?
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 8:37 am
by szucskrysz
i thought that the session is sent together with the http header between the client and the server every time a file is requested.
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 8:59 am
by jaoudestudios
Are memcached, APC as secure & efficient as sessions?
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 9:06 am
by Eran
Are they installed by default on php5?
No, they're PECL extensions. Just mentioning common alternatives
Are memcached, APC as secure & efficient as sessions?
They're more secure and efficient than sessions (in memory, no files).
Re: Singleton Pattern to store log in information
Posted: Mon Dec 15, 2008 5:01 pm
by pickle
Sessions are not the only PHP only option, cookies are also (technically) an option. If you only want persistence between pages, but want the data to be lost when the user closes their browser, then use sessions (I can't speak to memcache or APC - never used them).
Sessions can be hacked if you're not using an encrypted connection (and probably can even with an encrypted connection if the sneak is sneaky enough).
Session data is not transmitted off the server, but the cookie-based ID that is used as a key is transmitted. You should never be storing full credentials anywhere anyway - there should never be a need to store a password in a session.
Re: Singleton Pattern to store log in information
Posted: Mon Dec 22, 2008 6:18 am
by The_Anomaly
I agree with all that is said in this thread, but perhaps the OP is referring to using a Registry to wrap the Session variables, and make that Registry a Singleton?
That's at least what I do. I mean, I use a Session Registry for all interactions with the $_SESSION array, or anything that has to do with sessions (i.e. checking if authenticated, setting authentication status, userid, etc).
Is that perhaps what the OP is talking about?