Page 1 of 1
Quick Session Question...
Posted: Mon Aug 12, 2002 5:01 pm
by JPlush76
I'm new to sessions and I would basically like to make a page where a user can enter data(incuding user/name and password) and log in.
I have all that done already and my session works fine, but when I start making multiple pages checking for this session should I put the session check script in an include file as a function?
whats the most efficient way to have session checks on all your pages?
and also, the session is over when the browser is closed? is that right? so as long as that browser stays open the session will continue?
thanks!
Posted: Mon Aug 12, 2002 5:07 pm
by llimllib
If you register the user's name when he logs in, for example, with:
Code: Select all
$_SESSIONї'user_name'] = $user_name
and you want to check if a user's validated, just use:
Code: Select all
session_start();
if(isset($_SESSIONї'user_name']))
//user's been validated
else
//user not valid
Posted: Mon Aug 12, 2002 5:08 pm
by JPlush76
I meant, should I have that code on each individual page or should I use an include on each page?
Posted: Mon Aug 12, 2002 5:22 pm
by llimllib
now i see. It is much better style to use an include on each page. That way, you assist any caching that might be going on your server, as well as giving yourself only one place to change code. If you ever change your auth mechanism and it's included in a file 100 times, you only have to change it once. If it's in 100 files separately, well, you get the picture.
Posted: Mon Aug 12, 2002 5:26 pm
by JPlush76
coolio
so should it be its own include file or in my database connect include file?
and should it be a function in the include file?
mucho gracias

Posted: Mon Aug 12, 2002 5:31 pm
by llimllib
What file it is in should just be the file that makes the most sense to you. If you put it in a separate file, try to keep all unrelated functions in their own files. If you put it in the DB file make sure you change its name to reflect the fact that it's no longer a DB file, but a miscellaneous file. This only makes sense if you don't have many functions at all, but that may be the case.
As for functionalizing it, I highly recommend it, because any group of related instructions should generally be in a function.
paz y de nada
Posted: Mon Aug 12, 2002 5:32 pm
by JPlush76
also I get this long URL, whats the best way to hide this?
http://plush/ddev/temp/members_only.php ... 5e57f953c4
Posted: Mon Aug 12, 2002 5:48 pm
by llimllib
Hmmm....I read yesterday, but I forget where, an article that blamed it on session.use_trans_sid = 1. I really wish I could remember where that article was...