Page 1 of 1
How do you deal with logins?
Posted: Fri Sep 11, 2009 6:31 pm
by JellyFish
Hey, I was wondering how devneters usually go about dealing with session logins, just because I'd like to get an idea of all the different ways to do it. I know you store something in the $_SESSION variable, but what? The way I was thinking of doing it was this:
Code: Select all
$_SESSION['log'] = array(
"email" => $email,
"password" => $password,
...
);
and to check if a user is logged in:
Code: Select all
if ($_SESSION['log'])
{
//user is logged in
}
But now I'm tied up on what to call this array. Should I call it 'log' or should I call it 'login', 'logged', or 'user_log'?

Does it really matter? I guess not but I want something that makes sense. What do you do?
Thanks for reading.
Re: How do you deal with logins?
Posted: Fri Sep 11, 2009 7:28 pm
by requinix
It doesn't matter. And you can put whatever you want into $_SESSION.
You don't need a variable just to keep track if the user is logged in. Create a convention: if there is an [email] then the user logged in successfully, otherwise they did not.
Re: How do you deal with logins?
Posted: Fri Sep 11, 2009 8:00 pm
by JellyFish
tasairis wrote:It doesn't matter. And you can put whatever you want into $_SESSION.
You don't need a variable just to keep track if the user is logged in. Create a convention: if there is an [email] then the user logged in successfully, otherwise they did not.
I'm not so sure I know what you mean by convention. Do you mean check if $_SESSION['email'] is set instead of $_SESSION['login']?
Re: How do you deal with logins?
Posted: Fri Sep 11, 2009 10:12 pm
by requinix
It means you need to decide upon something and keep it standard across the website. Decide that (for example) $_SESSION["email"] will exist if and only if the user has logged in successfully.
The stuff with email versus login is a side-effect of what such a policy can do. Since you can use the email to check if a user logged in or not, you don't need an extra login variable.
Re: How do you deal with logins?
Posted: Fri Sep 11, 2009 11:27 pm
by Griven
If you're looking for ideas of what to call it, then you're likely going to get different answers depending on who you talk to. However, I think that most of us can agree on this: whatever you decide to call your variables, it should be something you'll be able to recognize six months down the road when you're revisiting this code.
For example, if you call your variable $_SESSION['log'], you may wonder what it means in the future. Were you talking about an event log? A log file? A block of wood?
Try to use a name that is self explanatory and points to the purpose of the variable, such as $_SESSION['loggedin'], ['email'], etc, etc.
Re: How do you deal with logins?
Posted: Sat Sep 12, 2009 2:54 am
by JellyFish
Okay, I'm going with $_SESSION['login']. Thanks for all the support.
