I have a login page which displays a login dialog once it has loaded. Login dialog's just a JQuery dialog that uses an Ajax call. Something like that:
$(function() {
    var _width = $.browser.msie ? 316 : 'auto';
    var loginDialog = $('#loginDialog');
    loginDialog.dialog({
        closeOnEscape: false,
        open: function() {
            $(this).parent().find('.ui-dialog-titlebar-close').hide();
        },
        resizable: false,
        position: 'center',
        stack: true,
        draggable: false,
        height: 'auto',
        width: _width,
        modal: true,
        buttons: {
            'submit': function() {
                $.ajax({
                type: 'post',
                dataType: 'html',
                url: '/ProjectName/Scripts/php/AccountController.php',
                cache: false,
                // async: false,
                data: $('#loginForm').serialize(),
                success: function(accessStatus) {
                    if(accessStatus === 'granted') {
                        loginDialog.dialog('close');
                    }
                },
                error: function(request, status, error) {
                    // handle it in a specific manner
                    alert(error);
                }
            });
        }
    }        
});
So if it's ok (on a server side) I just close the dialog.
Then in AccountController.php file as for now I have something like that:
<?php   
    session_start();
    if(IsAjaxRequest()) {
        if(isset($_REQUEST['username']) && isset($_REQUEST['password'])) {  
            require_once('LDAPHandler.php');
            // credentials
            $username = $_REQUEST['username'];
            $password = $_REQUEST['password'];
            // ... more parameters
            // ... Fetch against AD
            if(IsInAdminRole($username, $password)) {
                // ... establishing mysql connection & setting connection options
                // and then:                        
                mysql_query(
                    'insert into accounts'. 
                    '(login, sid) values({$username}, {session_id()})'.
                    'on duplicate key update sid=values(sid)'
                );
                // write response
                echo 'granted';
            }
        }
    }
?>
What I want is to store sid in the related record (Accounts table) in database. What makes me confused:
- As far as I understand if user duplicates some page after a successful login server will use the same session cookie? Am I right? Unless browser is closed.
- How do I handle the situation with different browsers?
- I read that wherever I need to use a session I must call session_start()on the page. Won't this give asiddifferent from one that is written during login?
- Say if I don't want duplicates, I mean user shouldn't access the same resource several times (simultaneously), which way is the best to handle that?
- Also I understand that I need to use some kind of a flag (possibly field in accounts table) to say that user is active, cause in other way I will store only the lastsid. Or better solution is to delete user from db once session has closed?
Huge Thanks!!
 
     
    