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 actions".
I want user to access my site functionality only when they are logged-in and redirect to login page when user is logged-out.
Thanks in advance.
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.
来源:https://stackoverflow.com/questions/8560940/log-in-log-out-user-status-with-lightopenid