Log Out Function
Permalink 3 users found helpfulI would like to place a "Sign Out" section into the footer of a C5 site I have built, does anyone know how to do this before I start drinking strong coffee and holding my eyes open with match sticks trying to do it myself?
Sorry but not a particularly great php coder but if anyone can point me in the right direction that would be awesome.
Thanks in advance

<?php $u = new User(); if($u->isLoggedIn()) { ?> <a href="<?=View::url('/login','logout');?>">Logout</a> <?php }else{ ?> <a href="<?=View::url('/login','login');?>">Login</a> <?php } ?>
And I agree with his method.
You don't want to logout while you are editing the particular page.
Perfect, absolutely spot on with what i was after, many thanks for your time and effort, very much appreciated.
So maybe something like this:
<?php $u = new User(); if($u->isLoggedIn() && !$c->isEditMode()) { ?> <a href="<?=View::url('/login','logout');?>">Logout</a> <?php }elseif(!$u->isLoggedIn()){ ?> <a href="<?=View::url('/login','login');?>">Login</a> <?php } ?>
I think that should do it. That just seems a bit easier to read to me semantically.
if(!$cp->canWrite() && !$cp->canAddSubContent()){
}?>
the edit bar isn't up so we can display the link, otherwise we don't want to display it without an explicit logout through the toolbar.
This code is used in concrete5 themes to drop the body down so images aren't pushed down by the toolbar like so:
$cp = new Permissions($c); if($cp->canWrite() && $cp->canAddSubContent()){ echo('<style type="text/css">body{background-position:0px 50px;}</style>'); }?>
Parse error: syntax error, unexpected T_STRING
Am I missing something? I placed in footer.php.
Thanks,
-mark
I tried this code but for some reason it didn't seem to work. If I clicked on the Log Out link it didn't - log me out I mean!
I altered the code slightly and now it works great.
The code I used is:
Hope this helps.
Tony.
-mark
When you login it will return to the collectionID of the page that forwarded them to the login singlepage.
Where do I put the code that I get from you? I'm not so good in PHP, sorry!
1. Get the cID of the page you'd like to forward to. So, if it's a newly created page named "Congratulations" with a cID of 200 (the cID parameter in the URL that shows up when you edit the page) then that's the number you care about.
2. Make a directory named login in the root blocks directory. Copy packages/login/blocks/login/view.php to this new directory.
3. Change this line:
<? if($returnToSamePage ){ ?>
<input type="hidden" name="rcID" id="rcID"
value="<?=$c->getCollectionID(); ?>" />
<? } ?>
in the template to
<? if($returnToSamePage ){ ?>
<input type="hidden" name="rcID" id="rcID" value="200" /> <? } ?> (or whatever the cID is) Now, you've modified the login block so that, regardless of what page it's currently on, it will forward to the congratulations page. This is a hack, but it shouldn't fork any core concrete stuff or anything, and it should work.
Hope this helps.
I'm suggesting yet another variation. (see code below)
There are really three states or conditions to LogIn/LogOut.
#1 Not Logged In, - show Login
#2 Logged-In, but Not in Edit Mode - show Logout
#3 Logged In and in Edit Mode - show message to Exit Edit Mode.
The issue I had with the original example was that during State#3, the Login was shown again. This was confusing.
Hope this helps,
Dennis
--------------------------------------------------------
<?php
$u = new User();
if (!$u->isRegistered()) {
print('<a href="'.$this->url('/login').'">Log In</a>');
} else {
print(' Hello: '.$u->getUserName().' ');
if (!$c->isEditMode()) {
print(' <a href="'.$this->url('/login','logout').'">Log Out</a>');
} else {
print(' Exit Edit Mode to logout ! ');
}
} ?>
I would like these to show the appropriate link based on the status of the user ie. Logged in or Logged Out.
I see that this function works in the footer but would like it in the Nav section.
Any suggestions where to add this code?
<?php $u = new User(); if (!$u->isRegistered()) { ?> <a href="<?= $this->url('/login'); ?>">Log In</a> <?php } else { print(' Hello ' . $u->getUserName() . ' '); if (!$c->isEditMode()) { ?> <a href="<?php echo URL::to('/login', 'logout', Loader::helper('validation/token')->generate('logout')) ?>"><?php echo t('Log Out.') ?></a> <?php } else { print(' Exit Edit Mode before logging out. '); } } ?>