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!
Quick Session Question...
Moderator: General Moderators
If you register the user's name when he logs in, for example, with: and you want to check if a user's validated, just use:
Code: Select all
$_SESSIONї'user_name'] = $user_nameCode: Select all
session_start();
if(isset($_SESSIONї'user_name']))
//user's been validated
else
//user not validnow 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.
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
As for functionalizing it, I highly recommend it, because any group of related instructions should generally be in a function.
paz y de nada
-
JPlush76
- Forum Regular
- Posts: 819
- Joined: Thu Aug 01, 2002 5:42 pm
- Location: Los Angeles, CA
- Contact:
also I get this long URL, whats the best way to hide this? 
http://plush/ddev/temp/members_only.php ... 5e57f953c4
http://plush/ddev/temp/members_only.php ... 5e57f953c4