Singleton Pattern to store log in information
Moderator: General Moderators
-
szucskrysz
- Forum Newbie
- Posts: 5
- Joined: Mon Dec 15, 2008 6:15 am
Singleton Pattern to store log in information
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
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
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Singleton Pattern to store log in information
Why must you use the singleton pattern?
-
szucskrysz
- Forum Newbie
- Posts: 5
- Joined: Mon Dec 15, 2008 6:15 am
Re: Singleton Pattern to store log in information
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.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Singleton Pattern to store log in information
The only way to transfer information between pages using php variables is to use sessions - that is what they are there for 
-
szucskrysz
- Forum Newbie
- Posts: 5
- Joined: Mon Dec 15, 2008 6:15 am
Re: Singleton Pattern to store log in information
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
Thanks again
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Singleton Pattern to store log in information
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.
Maybe someone else wants to shed some light on this.
But from my experience sessions are the way to go - fast & secure.
-
szucskrysz
- Forum Newbie
- Posts: 5
- Joined: Mon Dec 15, 2008 6:15 am
Re: Singleton Pattern to store log in information
I have read somewhere that you should not store sensitive data in session because they can be manipulated!?
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Singleton Pattern to store log in information
Are they installed by default on php5?
-
szucskrysz
- Forum Newbie
- Posts: 5
- Joined: Mon Dec 15, 2008 6:15 am
Re: Singleton Pattern to store log in information
i thought that the session is sent together with the http header between the client and the server every time a file is requested.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Singleton Pattern to store log in information
Are memcached, APC as secure & efficient as sessions?
Re: Singleton Pattern to store log in information
No, they're PECL extensions. Just mentioning common alternativesAre they installed by default on php5?
They're more secure and efficient than sessions (in memory, no files).Are memcached, APC as secure & efficient as sessions?
Re: Singleton Pattern to store log in information
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.
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- The_Anomaly
- Forum Contributor
- Posts: 196
- Joined: Fri Aug 08, 2008 4:56 pm
- Location: Tirana, Albania
Re: Singleton Pattern to store log in information
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?
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?