Jump to content
Larry Ullman's Book Forums

Having Trouble Establishing Sessions After Login In Modular Configuration


Recommended Posts

Edit: Nevermind do not worry about this thread.  Apparently my action attribute for my login form should have been "index.php?p=login".  When I give correct login info, it works correctly so I just need to fix the conditional for when the login info is incorrect.

 

Okay so I tried setting up a modular website with the standard header + left sidebar, content, and right sidebar + footer.  I also want to include the ability to register / login and put up a "Home | Login" or "Home | Settings" links up at the to of the header depending on whether someone is logged in or not.

 

Now, for some reason when someone logs in successfully and the $_SESSION array is supposed to take in the data from the users table and then head to index.php, it seems that the $_SESSION array is not being set at all... it is empty.  I am trying to figure out exactly what is going wrong here.

 

Here is part of my login page:

                if(mysqli_num_rows($user_check_result) == 1) { //start of valid single match
                    $_SESSION = mysqli_fetch_array($user_check_result, MYSQLI_ASSOC);

                    //update most recent log in
                    $last_logged_query = "UPDATE users SET last_logged_in = NOW() WHERE user_id = {$_SESSION['user_id']} LIMIT 1";
                    $last_logged_result = dbc_query ($dbc, $last_logged_query);
                    if(mysqli_affected_rows($dbc) != 1) { //if one row was not affected
                        $notes['last_logged_in_failure'] = "There was an error recording the login.";
                    }//end of one row not being affected

                    mysqli_free_result($user_check_result);
                    if(isset($last_logged_result)) mysqli_free_result($last_logged_result);
                    mysqli_close($dbc);
                    
                    $exit_url = BASE_URL . '/index.php';
                    header("Location: $exit_url");
                    exit();

                } 

Also, since the else clause after this if clause is not being executed, and the page is being redirected to index.php I assume that the $_SESSION variable is being set.  For some reason the redirect seems to be losing the $_SESSION array when it goes over to index.php.  I even had to separate the login.php script into a login.inc.calc.php script to be executed befor ethe header.php file and a login.inc.out.php to be executed after the header.php file since a redirect has to occur before HTML output.

 

A rar file of everything (except images) from my site (only 11kb because I just started it) is located here:

http://ipredict.danconia.us/ipredict.danconia.us.rar

 

This whole modular thing is making things a bit confusing and I'm wondering whether it's really worth it... if it might not be worth it to go back to the non-modular way of doing things.  On the other hand I don't want to back down from a good challenge.  Any help would be appreciated.  Thank you!

 

Edit:  Also, for the record the first real line in index.php is a require('./includes/config.inc.php'); and that config file's first line is start_session(); so I just don't get why that wouldn't be occurring:

/*
     * index.php (homepage) for http://iPredict.danconia.us
     * Script created by Kylan Hurt
     * http://kylan.danconia.us
     */
     
     require('./includes/config.inc.php');
     $errors = array();
     $notes = array();
     
Link to comment
Share on other sites

 Share

×
×
  • Create New...