Determine if user is logged in
Permalink 3 users found helpfulThanks
Cheers
/index.php/login/-/logout
<?php
global $u;
if ($u -> isLoggedIn ()) {
echo "<a href="http://www.sitename.com/index.php/login/-/logout"><input type="button" name="button1" value="logout" /></a>";
}
?>
if($uinfo->IsLoggedIn()){
echo('<a href="http://client.turnpostadmin.com/index.php/login/-/logout"><input type="button" name="button1" value="logout" /></a>');
} ?>
Global $u will usually work, but a new user object will always work :)
also i always wrap echo in the parenthesis (habit) and single quotes are your friend.
<?php $uinfo = new User(); if($uinfo->IsLoggedIn()){ ?> <a href="<?php echo DIR_REL?>/index.php/login/-/logout">Logout</a> | <a href="<?php echo $this->url('/profile')?>">My Profile</a> <?php } else { ?> <a href="<?php echo $this->url('/login')?>">Login</a> | <a href="<?php echo $this->url('/register')?>">Register</a> <?php }?>
something about horses and water..
its for core commerce add on.
shows different stuff if admin is logged in:
<div class="login"> <?php global $u; $u = new User(); global $cp; $canViewToolbar = (isset($cp) && ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage() || $cp->canApproveCollection())); if ($canViewToolbar) { $userName = '<br><a class="removeBtnStyle" href="' . $this->url('/index.php/dashboard/core_commerce/orders/search/') . '">Click to view orders</a>'; ?> <p class="loggedInAdmin"><?php echo 'Currently logged in as '; echo $u->getUserName().'. '; echo $userName;?> <a style="margin-left: 10px;" href="<?php echo $this->url('/login', 'logout')?>"><?php echo (' Sign Out')?></a></p> <?php } elseif (!$u->getUserName()) { ?> <p class="notLoggedIn">You are not logged in<a href="<?php echo $this->url('/login')?>"><?php echo (' Sign In')?></a></p> <?php