basic help on sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gimpact
Forum Commoner
Posts: 65
Joined: Tue Jun 16, 2009 11:08 pm

basic help on sessions

Post by gimpact »

Hello,

For the first time I am creating a user/member login script. I am using session to store info about all logged in user. Here is what I would like to know,

lets say, the user is logged in and the following code executed

Code: Select all

 
session_start();
$_session['email']= $email;
 
a. how long will this session last? to prevent excessive server usage when the user is away from the computer, I would like to kill the session. Is there a way?

b. whats best to store in session? an email id? I was wondering if I know some one else email, can I try to use his email, in my session when I am logged it?

c. should i go for a complex numeric data and store it in session for remember logged in user?

Thank you for reading this
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: basic help on sessions

Post by requinix »

gimpact wrote:a. how long will this session last? to prevent excessive server usage when the user is away from the computer, I would like to kill the session. Is there a way?
Not really, and it's not worth it. PHP will clean up old sessions automatically. "old" is a per-server thing: typical values are 5, 15, or 30 minutes.
gimpact wrote:b. whats best to store in session? an email id? I was wondering if I know some one else email, can I try to use his email, in my session when I am logged it?
Store whatever you want, hopefully to cut down on the number of database queries you have to run.
Users can't see or touch session data - only your code.
gimpact wrote:c. should i go for a complex numeric data and store it in session for remember logged in user?
What?

"Remember me" things store some information in cookies, then use that to log in if it's present and there's no session information yet.
gimpact
Forum Commoner
Posts: 65
Joined: Tue Jun 16, 2009 11:08 pm

Re: basic help on sessions

Post by gimpact »

Thanks for the info

the 3rd question is related to 2nd question. I was wondering how much can I actually store in session without my server being over loaded with session. The person for whom i am trying to make this, says he expects at least 1000 visitors a day. so i got the be careful not to make my servers go for running computing power for many sessions.
gimpact
Forum Commoner
Posts: 65
Joined: Tue Jun 16, 2009 11:08 pm

Re: basic help on sessions

Post by gimpact »

I have one more question to ask.

This is how I am expecting my pages to work once the user is logged in

login page
http://www.x.com/members/login/index.php

after success full login
http://www.x.com/members/login/account/?tag=home

now here, this page actually includes another page which is located here

http://www.x.com/members/login/account/PAGES/home.html

in "account/index.php" i am making a check for session. if no session user is redirected, if there is session the "home.html" gets loaded. I was wondering is it really necessary to make another session check with in "home.html"? my "PAGES" folder is hidden in the server from public views.

Thank you,
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: basic help on sessions

Post by requinix »

gimpact wrote:I was wondering how much can I actually store in session without my server being over loaded with session.
Like I said, store whatever you want.
gimpact wrote:I was wondering is it really necessary to make another session check with in "home.html"? my "PAGES" folder is hidden in the server from public views.
Hidden or inaccessible?

If you can't get to home.html any other way then you can make index.php handle all the work.
Post Reply