Page 1 of 2

Login / Logout Link

Posted: Sat Sep 13, 2008 9:08 am
by Jojomofo
Hi Guys,

At the moment i have a login form on my template as default by joomla. I feel it takes up space of my template. How can i have a Login / Logout link? Most sites have these. So when you login it will display something like "account / logout" and when loged out it will display "login"

Thanks for any help! :)

Re: Login / Logout Link

Posted: Wed Sep 17, 2008 7:11 pm
by shinta2
I'm also interested in this. I've searched the forums and the web for this issue, but I've found no working solution for 1.5. I've only found posts asking this question, like this one ;)

BTW, "index.php?com_user&task=logout" doesn't seem to work anymore; I remember it used to? All I really need is a way to create a menu link that logs out the user, then I can use some simple php in the template to toggle between the two. But I don't know what the link should be for a "logout" menu item, or if there's a buil-in menu item type like there is for "login."

Thanks.

Re: Login / Logout Link

Posted: Thu Sep 25, 2008 4:04 pm
by j916
Did you have any luck in finding a solution? I just started looking for the same thing.

-Jeff

Re: Login / Logout Link

Posted: Sun Nov 02, 2008 10:08 am
by blackmagic911
I also have the same question. It would make my frontpage much more simple. any answers?

Re: Login / Logout Link

Posted: Sun Nov 02, 2008 5:19 pm
by refernow
I have created a Request Form for clients but can't find a way to create a text link. Please share if you got solution.

Re: Login / Logout Link

Posted: Fri Nov 07, 2008 5:20 am
by redmars
If your just wanting to add a link in your html code, you just need to put this link if you have Search Engine Friendly URLs turned on.
http://www.yourdomain.com/logout.html

In one of my site I have added a logout link in the main menu, using the "Default Login Layout" for the Menu Item Type. It shows up as logout when a user is logged in.

Image

Re: Login / Logout Link

Posted: Fri Dec 19, 2008 7:49 pm
by tr2n
This works:
/index.php?option=com_user&view=login&task=logout

Hope it helps.. :pop

Re: Login / Logout Link

Posted: Fri Jan 23, 2009 8:28 pm
by Whitebread
thanks tr2n...

This worked well for me with one exception, when I logout it takes me to a blank page and stays there. Is there any code that could be added to that link that would re-direct me to a certain page? say, the login page?

Re: Login / Logout Link

Posted: Fri Jan 23, 2009 9:34 pm
by tr2n
Umm.. I'm guessing a redirect to another page must be added into the logout task of the com_user controller.php file.. lemme check and see if it works.

Re: Login / Logout Link

Posted: Wed Feb 04, 2009 10:26 am
by fr33lanc3
This page will explain about the logout link redirect.
http://forum.joomla.org/viewtopic.php?f=428&t=334765

Re: Login / Logout Link

Posted: Wed Feb 04, 2009 10:32 am
by fr33lanc3
Also, this is link text for login:

index.php?option=com_user&view=login&Itemid=33

Re: Login / Logout Link

Posted: Wed Feb 04, 2009 4:50 pm
by tr2n
Yay, the info on that post works great, use this link instead to return to the index:

index.php?option=com_user&task=logout&return=Lw

Re: Login / Logout Link

Posted: Wed Mar 25, 2009 2:25 pm
by frankzusa
Thank to tr2n for the link!!! Cheer!

Re: Login / Logout Link

Posted: Wed Apr 29, 2009 11:08 pm
by chilts
good post. was looking exactly for this. thanks.

Re: Login / Logout Link

Posted: Thu Apr 30, 2009 4:38 pm
by njjacob
actually just use

http://www.yourdomain.com/index.php?option=com_login for the login...

Re: Login / Logout Link

Posted: Thu Apr 30, 2009 5:12 pm
by tr2n
Yeah, without &Itemid for the login.. actually for any generic link :) adjust the Itemid for your own site.

Re: Login / Logout Link

Posted: Tue Jun 16, 2009 1:00 pm
by imscoop22
For the original question, see if this helps. I wrote it because a variation of this question was posted again recently.

http://www.joomlafare.com/joomla/joomla ... -to-logout

Re: Login / Logout Link

Posted: Thu Dec 17, 2009 1:06 am
by peterleslie
tr2n - many thanks your post solved a problem that has been bugging me re-direct logout link

muchos gracias

Re: Login / Logout Link

Posted: Thu Feb 18, 2010 12:07 pm
by msibley
Thanks tr2n, your method worked a treat except for one slight issue. The home URL for my particular installation wasn't the root as Joomla was installed in a sub-folder which meant I was getting redirected to the parent directory on logout. The solution is easy enough though:

Code: Select all

<a href="index.php?option=com_user&task=logout&return=<?php echo $returnURL; ?>">Logout</a>
Then just set $returnURL to the homepage using:

Code: Select all

$returnURL = base64_encode(JURI::root() . "\n");

Re: Login / Logout Link

Posted: Fri Jun 11, 2010 11:16 pm
by emediately
How can I make the same login button that RETURNS to the SAME page the user was on after loggining in???

Because it's pointless if some browses your site and they need to login at a point, and then all of a sudden it directs them to the homepage of my website..

Please help.. What's the PHP query (return url) for the same url the user was on before logging in?

Also.. What changes do I need to make in the core to change the login page so it would direct to the page the user was on?
msibley wrote:Thanks tr2n, your method worked a treat except for one slight issue. The home URL for my particular installation wasn't the root as Joomla was installed in a sub-folder which meant I was getting redirected to the parent directory on logout. The solution is easy enough though:

Code: Select all

<a href="index.php?option=com_user&task=logout&return=<?php echo $returnURL; ?>">Logout</a>
Then just set $returnURL to the homepage using:

Code: Select all

$returnURL = base64_encode(JURI::root() . "\n");

Re: Login / Logout Link

Posted: Mon Jul 05, 2010 9:31 am
by rtenhave34
@ emediately: Sorry, I do not have the answer to your query....

@ All:

I have been playing around with this as I was facing the same issue. No coding needed (in the end) to get exactly what I wanted though (providing your return page can be the homepage of your site).....

1. Create a Login link (Public) in one of your exsisting menu's
2. Create a "User Menu" (Registered) which will show up when logged in
3. Put all relevant menu choices in there (Edit, Lost Password, etc)
4. Create a "Login"menu item, but name it "Logout" and set it to "Registered"

Now, the Logout menu option will appear in the User Menu, only when logged in, and when clicked it will tell you that you are logged in, but will show a Logout button on the same page.

PS, Dont forget to set your Landing and End URL's in the "Login" option panel!

Presto!

Re: Login / Logout Link

Posted: Fri Aug 13, 2010 3:18 pm
by djohnson1215
Nice. Very good discussion. Good thinking rtenhave34.

But my need is just a little different. My client wants a link (not a menu item) to change from login to logout. The link would be dynamic depending on whether a user is login already. When not logged in, the link would read "login". After login, the link would read "logout" and apply the URL path in earlier posts to log the user out.

I know how to do this in a menu item thanks to rtenhave34's suggestions. But how would I do this for a typical <a> tag link. My suspicion is that this will take some php which I really don't know well.

As an alternative, the link could be a image button. The first button would be a login button. When the user is logged in, they see the logout button.

Again, I am not a PHP programmer, but I am sure some of the subscribers to this thread are. So I am appealing to those who would like to take up the challenge and write a little code to make this work. It would be a really nice addition to Joomla sites.

After a bit of research, I have found the JFactory function that looks like it would work: http://docs.joomla.org/JFactory/getUser.

I am just guessing, but I suspect the PHP code needs to look something like this:

Code: Select all

<?php $user =& JFactory::getUser(); 
if ($user->id == 0){   
echo '<a href="/registration-login.html" >Login</a>';} 
else {   
echo '<a href="/index.php?option=com_user&task=logout&return=Lw" >Logout</a>';} 
?> 
Now, how do you get this php code into an article running joomla 1.5.20? Anyone up for a challenge?

Re: Login / Logout Link

Posted: Fri Aug 13, 2010 11:14 pm
by djohnson1215
It worked!!!!

Had to make a module with Jumi to get PHP to work. And then had to put all the other links in the head nav inside the php, but it worked!

Final Code:

Code: Select all

<?php $user =& JFactory::getUser(); 
if ($user->id == 0){   
echo '<p style="margin-right:30px; padding:5px 0 10px 0; color: #ffffff; font-size: 13px; font-weight: 900;"><a target="_self" title="All About FoIP Home" href="http://www.allaboutfoip.com/">Home</a> |<a title="About Us" href="/about-us.html">About Us</a> | <a href="/contact-us.html">Contact Us</a>       <a><span style="color: #0000ff;"> </span></a> <a  class="login_lnk" target="_self" title="Login" href="/registration-login.html"><img src="images/allaboutfoip/login.png" alt="" height="20px width="60px" /></a></p>';} 
else {   
echo '<p style="margin-right:30px; padding:5px 0 10px 0; color: #ffffff; font-size: 13px; font-weight: 900;"><a target="_self" title="All About FoIP Home" href="http://www.allaboutfoip.com/">Home</a> |<a title="About Us" href="/about-us.html">About Us</a> | <a href="/contact-us.html">Contact Us</a> <a><span style="color: #0000ff;"> </span></a>      <a class="logout_lnk" target="_self" title="Logout" href="/index.php?option=com_user&task=logout&return=Lw" ><img src="images/allaboutfoip/logout.png" alt="" height="20px width="60px" /></a></p>';} 
?>
See it in top right here: http://www.allaboutfoip.com/

PHP programmer level .01 strikes again :-)

Re: Login / Logout Link

Posted: Sat Aug 14, 2010 1:01 am
by imscoop22
It's interesting that this thread pops back up every now and then.

@djohnson1215 - You can use MetaMod to swap modules like I described in the link I posted earlier in this thread. The modules you "swap" do not need to be menu modules...they could just be Custom HTML modules. I think that would be a bit easier to manage than the method you used.

Re: Login / Logout Link

Posted: Mon Aug 16, 2010 3:04 pm
by djohnson1215
Hi imscoop22,

I just checked "MetaMod". Very nice. It does look like "MetaMod" would do the same thing since it claims to:

"show/hide modules for individual users, guests, logged-in users, or any user group"

Nice find. Will definitely keep this module in mind for next time. Tks for the heads up!

Re: Login / Logout Link

Posted: Mon Sep 20, 2010 9:19 pm
by Tzakuk

Re: Login / Logout Link

Posted: Mon Jun 06, 2011 3:18 am
by wwwstalcup
I have also found in 1.5.23 if you use this for front side access:
<a href="index.php?option=com_user&view=login">Login-Logout</a> to create your link it will log them & go back to home page (even if that's in a sub-dir) but not the page they were on. So, a user can login and then navigate to edit - which was what my client wanted to do ( or whatever else "logged in" brings on your site). If they click the Login-Logout link again but are logged in, they get the logout screen, & on doing so return to the site local home page (even if in a sub-dir).

might be a simple alt for some sites.

Wes.

Re: Login / Logout Link

Posted: Sat Mar 03, 2012 8:10 am
by FranCardin
People who are still struggling with this please check-out this tutorial
http://docs.joomla.org/Access_Control_L ... nd_Modules
to create 'Guest' User Group.

After you create the above 'Guest' user group, Create two 'Login' Menus.
One you name as 'Login' and Set access level to 'Guest'
and the second one rename as 'Logout' & Set access level to 'Registered'

That's it. You can keep 'ordering' of the two menu to close to each other. (See the attached image)
login_logout.jpg
Now, after you log in from the frontend you will see that the 'Login' menu automatically changes to 'Logout'

Thanks.

Re: Login / Logout Link

Posted: Tue Apr 17, 2012 11:25 am
by deadlydave
please note the above post only applies to joomla 1.6 and above

Re: Login / Logout Link

Posted: Sun Jul 22, 2012 7:30 pm
by merc911
In which case is there anythig for 2.5?.
I have a login menu button. I cant see how to create a logout button.