Elxis CMS Forum
Support => General => Topic started by: ROUBOS on July 02, 2012, 20:15:40
-
Hi,
I've used the if statement to check if we're on a certain component page in order to display or hide part of the template, is there an if statement to check wether the user is loged on and display a logout button?
I want to use a login and a logout button. So that when the user is loged on, then the logout button appears.
any thoughts???
thanks.
-
Hi Roubos,
Yes you can do that with this way :
if ($my->id) {
echo '<img src="logout.png" alt="Log out" width="300" height="50" />'."\n";
} else {
echo '<img src="login.png" alt="Log out" width="300" height="50" />'."\n";
}
In case that you are going to include the above piece of code at the index.php file of your template then there is no need to define the global variable $my. In any other case you should define it like this :
global $my;
On Elxis Nautilus relative way :
if (eFactory::getElxis()->user()->gid != 7) {
echo '<img src="logout.png" alt="Log out" width="300" height="50" />'."\n";
} else {
echo '<img src="login.png" alt="Log out" width="300" height="50" />'."\n";
}
*Set the exact width and height of your image source inside img tag.
-
thank you :)
-
Checking access level value, to determine if a user is logged in or not, is not always safe on Nautilus.
You better check uid (user id, greater than zero for elxis users) or gid (group id, unequal to 7 - guests- and optionally to 6 - external users).
Conclusion
$elxis->user()->uid > 0 The user is logged in via Elxis Authentication.
$elxis->user()->uid = 0 The user is a guest or logged in via external authentication provider (LDAP, twitter, gmail, etc).
$elxis->user()->gid == 7 The user is a guest
$elxis->user()->gid == 6 The user is logged in via external authentication provider.
else the user is logged in via Elxis authentication.
-
Right Datahell! It was my fault. It's totally recommended the use of either uid or gid .