Want to display a specific page to a user when they login to Joomla? Here's how!


Category: joomla

Introduction

With Joomla (1.0, 1.1), there are some optional modules to give this functionality - allowing a specific register user to have their own page. For example there is User Home Pages or Community Builder, however, sometimes these are overkill for what is a very simple problem - how to have a specific user view/redirected to a specific page when they log in.

I came across this solution on the Joomla Forums and have modified it slightly for our use. It allows you to select a specific page from a drop down that the user will be redirected to upon login and logout.

Solution

Step 1:

open the file: /administrator/components/com_users/users.xml
after line 13 find:
<param name="editor" type="editor_list" default="" label="User Editor" description="WYSYWYG Editor for this User" />

add:

<param name="login" type="page_list" default="" label="Login Redirection URL" description="What page will the login redirect to after user login, if let blank will load module default" /> <param name="logout" type="page_list" default="" label="Logout Redirection URL" description="What page will the login redirect to after user logout, if let blank will load module default" />

Step 2:

open file /index.php
around line 139 replace:
$mainframe->login();

with:

$mainframe->login(); // Per User Redirection $temp_my = $mainframe->getUser(); $params = new mosParameters( $temp_my->params ); $userRedirect = $params->get( 'login', '' ); if ($userRedirect) { $return = sefRelToAbs( "index.php?option=com_content&task=view&id=" . $userRedirect . "&Itemid=" . $userRedirect ); } $temp_my = '';

around line 168 replace:

$mainframe->logout();
with:
// Per User Redirection $temp_my = $mainframe->getUser(); $params = new mosParameters( $temp_my->params ); $userRedirect = $params->get( 'logout', '' ); if ($userRedirect) { $return = sefRelToAbs( "index.php?option=com_content&task=view&id=" . $userRedirect . "&Itemid=" . $userRedirect ); } $temp_my = ''; $mainframe->logout();

Step 3:

open file /administrator/components/com_users/users.class.php
around line 47 add:
function _form_page_list( $name, $value, &$node, $control_name ) { global $database; // compile list of the pages $query = "SELECT id AS value, title AS text FROM jos_content" ; $database->setQuery( $query ); $editors = $database->loadObjectList(); array_unshift( $editors, mosHTML::makeOption( '', '- Select Page -' ) ); return mosHTML::selectList( $editors, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value ); }

And you're good to go!

Summary

It's a nice quick hack. You can create a new page in the admin, set that page to registered then allow the user to drop straight in on that page so in effect it's their own 'custom' homepage. It would take a registered user 'guessing' the pageid/link to come across otherwise. Not perfect, but useful for such a quick hack. The limitation is on the screen it brings up - it's currently drawn flat. If you want to customise it with specific menus/layouts then edit the bit of code that creates the redirect in index.php with your own item/menu ids.

Alternatively, to get round this, you could replace the two calls to type="page_list" in the xml with type="text" and replace the two $return = sefRelToAbs( "index.php?option=com_content&task=view&id=" . $userRedirect . "&Itemid=" . $userRedirect ); with $return = sefRelToAbs( $userRedirect ); to have a raw text input. This would allow you to input any url you wish.

 


Comments

I don't see that code in

I don't see that code in index.php either?
am I in in the right directory?

Hi

Just want to thank you for very informative post, regards Ed

Hi Dan, It is in the root

Hi Dan,

It is in the root index.php (ie. base directory), around line #146 below the

// Get the information about the current user from the sessions table

Cheers!
Graeme.

Step 1 issue

You say to edit /administrator/components/com_users/users.xml , but I don't see anywhere in this file.

which version of Joomla are you using?

Hi Dan,

The hack is compatible with Joomla 1.0/1.1, not the new 1.5 branch :)

Cheers!
Graeme.

Linking

Is there a way to also make a link in the user menu to this page. Once they leave this page, and browse, I want them to be able to return to it. Thanks

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.