Log-in/log-out user status with LightOpenID

*爱你&永不变心* 提交于 2019-12-01 01:36:47

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!