Home
PDF Print E-mail
Written by Administrator   
Tuesday, 18 May 2010 13:43

How to create link to login, logout, register page in Joomla?

 

It often happens that customers do not need a registration page, but after a while, there are additional opportunities at the site requires registration page, as well as the landing page. So, how to add these links to our Joomla template?

 

Here is URLs for our:

 

Login page: http://www.YourSiteName.com/index.php?option=com_user&view=login

Logout page: http://www.YourSiteNome.com/index.php?option=com_user&view=logout

Register page: http://www.YourSiteName.com/index.php?option=com_user&view=register

 

If we want to add a bit of user interactivity then we first need to get the users name with a JFactory call and store it in a variable which we place in the php section of the template:

 



$username =& JFactory::getUser();

 

Then we can use this to show Register, Login links or Logout link, it depends of user logged in or not.

 



<div id="loginArea">
<?php
 if ($username->guest) {
 echo '<a href="http://www.YourSiteName.com/index.php?option=com_user&view=register" title="Register">Refister</a> ';
 echo '<a href="http://www.YourSiteName.com/index.php?option=com_user&view=login" title="Login">Login</a>';
   } else {
   $name = $username->get('username');
   echo 'Hi ' . $name . ' -  <a href="http://www.YourSiteNome.com/index.php?option=com_user&view=logout" title="Logout">Logout</a>';
   }
 ?>
</div><!-- End Login Area -->

 

I hope it will be useful for you :)


Last Updated on Tuesday, 18 May 2010 13:51
 

Comments 

 
#1 2010-11-19 09:56
huh?

If we want to add a bit of user interactivity then we first need to get the users name with a JFactory call and store it in a variable which we place in the php section of the template:?

Where di i find this
Quote
 
 
#2 2010-12-14 17:05
You can add this code here:
/templates/YourThemeName/index.php

< ? php $ username = & JFactory : : getUser ( ) ; ? >

(remove spaces)
Quote
 
 
#3 geoff rogers 2011-05-02 12:16
Just added this to one of my own websites and it works really well - thanks for posting this.
Quote
 

Add comment


Security code
Refresh

© 2010. Sopov.com