PHPremote Posted March 12, 2019 Share Posted March 12, 2019 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 More sharing options...
justsomeguy Posted March 12, 2019 Share Posted March 12, 2019 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 More sharing options...
PHPremote Posted May 20, 2019 Author Share Posted May 20, 2019 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 More sharing options...
justsomeguy Posted May 20, 2019 Share Posted May 20, 2019 Why are you checking for the cookie? Just start the session and use it. Link to comment Share on other sites More sharing options...
Funce Posted May 20, 2019 Share Posted May 20, 2019 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now