Jump to content

need overall algorithm or sequence for login test using sessions


PHPremote
 Share

Recommended Posts

I need an overall algorithm or sequence for login test using sessions. I am all turned around. I had to make up my own flowchart on paper.

To access the username, for example, once the user is already logged in, I put a session_start() at the beginning of the site header script, called from within a page like "search.php". But to log in or out, I need to access it before that. I think I need to put session_start() at the beginning of each individual page.

Passing variables like SESSION['validlogin'] seems to be haphazard, but I think that is a logic error somewhere.

I was trying to make it really elegant before, with a single redirection script once logged in, but that was not working. So, back to basics.

Link to comment
Share on other sites

I think I need to put session_start() at the beginning of each individual page.

You do.  It's common to have one or more files that every other file will include, files that do things like set up a database connection, define variables or functions that might be used on any page, and start the session.

Link to comment
Share on other sites

  • 2 months later...

I was also starting the session in my login script also, with an

Quote

if (isset($_COOKIE['PHPSESSID')]) {

session_start();

}

but that is not reliable. I have disabled that for now, but I doubt the session variables will always get passed as needed.

Link to comment
Share on other sites

If you think you're going to be activating sessions more than once in a page (by method of including code that uses it) you can check this condition

<?php
if (session_status() === PHP_SESSION_NONE) {
  session_start();
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...