Log-in/log-out user status with LightOpenID

后端 未结 1 1590
南笙
南笙 2021-01-07 11:51

I m trying to use LightOpenId for my site to log-in/log-out users. This works fine but my question is \"How can I track user log-in/log-out status and take respective action

相关标签:
1条回答
  • 2021-01-07 11:57

    Your question has actually nothing to do with OpenID.

    OpenID is an authentication protocol, meaning that it only checks whether the user really is who he claims to be -- in the same sense that asking for a password checks that. It has nothing do to with your user being logged in or out.

    In order to keep track of your user's session you need to, well, use sessions. For example, after validation:

    <?php
    if($openid->validate()) {
        // User has logged in
        $_SESSION['identity'] = $openid->identity;
    }
    ?>
    

    Then when you want to check whether your user is logged in (and who is he):

    <?php
    if(isset($_SESSION['identity'])) {
        echo 'User is logged in as ' . $_SESSION['identity'];
    } else {
        echo 'User isn\'t logged in';
    }
    ?>
    

    And for the sake of completion, when logging out:

    <?php
    unset($_SESSION['identity']);
    session_destroy();
    ?>
    

    If you don't know how to use sessions, you can find more information in the manual.

    0 讨论(0)
提交回复
热议问题