Actions

Talk

Difference between revisions of "Auto redirect guests to login"

From Joomla! Documentation

(New page: I'm developing a component that I want to be visible to all but force the user to log in before using it. I am using the following code in the default php file that my component runs upon...)
 
Line 3: Line 3:
 
<code>   
 
<code>   
 
$user  = & JFactory::getUser();
 
$user  = & JFactory::getUser();
   if (($user->get('id')) < 1)
+
   if ($user->guest)
 
   {
 
   {
 
     $forceLoginController = new JController;
 
     $forceLoginController = new JController;

Revision as of 07:02, 3 September 2008

I'm developing a component that I want to be visible to all but force the user to log in before using it. I am using the following code in the default php file that my component runs upon loading.

$user = & JFactory::getUser();

 if ($user->guest)
 {
   $forceLoginController = new JController;
   $forceLoginController->setRedirect('index.php?option=com_user&view=login');
   $forceLoginController->redirect();
 }

I'm pretty much a Joomla! noob, but I don't see any reason why this shouldn't be used.