php screen lock page code?

Discussion in 'PHP' started by ameerulislam43, Sep 18, 2013.

  1. #1
    Hi,

    I got a design where it has a screen lock functionality. Now how can I create a screen lock that will basically make the user partially logout. i.e. his username email address etc still going to be shown on the lock screen, just like windows but he would need to retype his password to get access to the site again. I have spent the whole day searching clue for this without success.

    EDIT: One more note, there is actually a link where if clicked the user is taken to the screen lock page. I'm mentioning this so you guys don't suggest about session time expiration.

    Thanks
     
    Last edited: Sep 18, 2013
    ameerulislam43, Sep 18, 2013 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Its possible with javascript. Load a timer and everytime the mouse or keyboard makes a move you need to reset the 'counter'. When the timer is at its limit, or a. redirect to another page... or b. show a fullscreen div with login info that will check with ajax if current session is same as given login information.

    Not realy hard, but takes time.
     
    EricBruggema, Sep 18, 2013 IP
  3. ameerulislam43

    ameerulislam43 Active Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #3
    As I mentioned in my edit I have a link to click, so how can that help? I'm thinking of unsettling certain variables in the session.. But I'm not sure it will work or not.
     
    ameerulislam43, Sep 18, 2013 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #4
    What for is that link? please describe in full :)
     
    EricBruggema, Sep 18, 2013 IP
  5. Basti

    Basti Active Member

    Messages:
    625
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    90
    #5
    Hmm, have you tried ajax?
    Once you click your link, make a request to a ajax file
    1. The on click event needs to pass his unique user id
    2. on the ajax file first check if his user id is equal to his logged in id
    3. if it is, grab database info such as username, email ( so no wrong info or info from another user can be shown )
    4. log the user out in the ajax file
    5. in the ajax success function, check for the response and set up your screen lock with some info

    something along the line of
    
        $('#link_id').on('click', function() {
                    $.ajax({
                        type: "GET",
                        url: "/ajax.php",
                        data: { user_id: "The uses id here" },
                        dataType: "json"
                    }).success(function(response) {
    
                        // Do you screenlock here
                        // username is response.username
                        // email is response.email
    
                    });
        });
    
    HTML:
    <?php
    
    // Include any needed files you may have, such as db connection details or what not
    
    // Check for correct id, if not exit script
    $user_id = intval($_GET['user_id']);
    
    if($user_id != logged_in_userId() ) {
        exit;
    }
    
    // DB query here to fetch this user details
    
    // Encode response as json
    $response = array('username' => 'db_grabbed_username', 'email' => 'db_grabbed_email');
    
    // Data is now here, lets log user out, maybe you have a function for that
    logoutUser($id);
    
    echo json_encode($response);
    
    ?>
    PHP:
     
    Basti, Sep 19, 2013 IP