Elxis CMS Forum
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Download Elxis CMS: Elxis 4.0 Nautilus
 
Pages: [1]
  Print  
Author Topic: if statement for login check? [SOLVED]  (Read 1019 times)
ROUBOS
Hero Member
*****
Offline Offline

Posts: 627



« on: July 02, 2012, 19: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.
« Last Edit: July 02, 2012, 19:32:43 by ROUBOS » Logged
webgift
Elxis Team
Hero Member
*****
Offline Offline

Posts: 3263



WWW
« Reply #1 on: July 02, 2012, 19:27:49 »

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.
« Last Edit: July 03, 2012, 17:18:06 by webgift » Logged

ROUBOS
Hero Member
*****
Offline Offline

Posts: 627



« Reply #2 on: July 02, 2012, 19:32:52 »

thank you Smiley
Logged
datahell
Elxis Team
Hero Member
*****
Offline Offline

Posts: 7596



WWW
« Reply #3 on: July 02, 2012, 20:12:57 »

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.
« Last Edit: July 02, 2012, 20:15:39 by datahell » Logged

webgift
Elxis Team
Hero Member
*****
Offline Offline

Posts: 3263



WWW
« Reply #4 on: July 03, 2012, 11:06:51 »

Right Datahell! It was my fault. It's totally recommended the use of either uid or gid .
« Last Edit: July 03, 2012, 17:19:06 by webgift » Logged

Pages: [1]
  Print  
 
Jump to: