Sessions in PHP are no where near as tough as you're thinking they are.
At the beginning of any script that is going to use session variables, issue session_start().
Any variable that you want to use as a session variable, use session_register() on the name of that variable. For example, if you have a variable called $username, perform session_register("username".
Once a variable has been registered with a session, it will be available as $_SESSION["username"] if you have "register_globals" set to "off" in php.ini, and both in $_SESSION["username"] and as $username if "register_globals" is set to "on".
Once your done with a particular session variable, perform session_unregister("username".
the part that has me confused is when im going from the login page to the other pages. And how to verify a user is logged in when loading theother pages so you cannot just do a direct call to it and have it work.
What I've done is have the login page, once the user's credentials are verified, set a session variable called "login_id", which is the auto_increment ID for that user's record in the user table.
When later pages issue sestion_start(), they can then check for the presence of $_SESSION["login_id"] to know whether the user is correctly logged in, and use that variable's value to know who the user is. Conversely, if the variable does not exist, other pages can redirect the browser to the login page.
______________________________________________________________________
TANSTAAFL!
Sessions do expire. If the user is logged in and the session expires, the site will forget who he is. You need to make sure your scripts can handle this gracefully. ______________________________________________________________________
TANSTAAFL!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.