Ok, so I've got an authentication/login form that is "powered by" ajax.  The
user logs in, is authenticated, and the last step is to start a session and
save the necessary information in the $_SESSION vars.

For some reason, it appears (and almost of makes sense) that the session
that is started via the AJAX is lost once the ajax is complete. 

AJAX calls the php, passing username and password
Php executes all the necessary authentication, etc etc
If, login is valid, it calls mySessionStart() (see below)
Checks to make sure the session has been started using isLoggedIn() (below),
which returns true
AJAX closes, receiving a "successfully logged in" message.
AJAX turns around and makes a second call, calling isLoggedIn() again, and
the session is gone

What I'm *guessing* is that because the PHP is not running on the active
page, but "in the background" the session is not being set for the active
page.  Is there a way to pass the session back to the browser?

-       John


Debugging code has been removed for readability:
**********************************

function mySessionStart($persist, $sessionID, $sessionKey, $debug=0){

        session_start();

        $_SESSION['sessDBID'] = $ sessionID;
        $_SESSION['sessKey'] = $ sessionKey;
        $_SESSION['persist'] = $persist;
        
        // if persist, set cookie
        if ($persist){
                return myCreateCookie($persist, $ sessionID, $ sessionKey,
$debug);
        }else{
                return true;
        }
}


********************************



function isLoggedIn($debug = 0){
                
        global $COOKIE_NAME;
        
        // if there is an active session.
        if (isset($_SESSION) && $_SESSION['sessDBID'] != '' &&
$_SESSION['sessKey'] != ""){

                //. check the contents
                return authenticate($_SESSION['sessDBID'],
$_SESSION['sessKey']);
        
        // or, check for (persistent) cookie.
        }elseif (isset($_COOKIE[$COOKIE_NAME]) && $_COOKIE[$COOKIE_NAME] !=
""){
                
                $sessInfo = split('-', $_COOKIE[$COOKIE_NAME]);

                // . and check the contents
                if(authenticate($sessInfo[1], $sessInfo[0], $debug)){

                        // reset the cookie
                        mySessionStart(true, $sessInfo[1], $sessInfo[0],
$debug);
                }else{
                        // cookie authentication failed
                        return false;
                }

        }else{
                // there is no session or cookie
                return false;
}
}

Reply via email to