[RESOURCE]Force login before access to site - my solution

General questions relating to Joomla! There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
User avatar
toubkal
Joomla! Hero
Joomla! Hero
Posts: 2860
Joined: Thu Aug 18, 2005 4:35 pm
Location: Cheshire, England
Contact:

[RESOURCE]Force login before access to site - my solution

Post by toubkal » Wed Aug 24, 2005 10:18 pm

I am sure that this has been done before, but I was quite pleased with the result so I thought that I would show you how I created a template which forces a login before access to the site.

basicaaly a couple of php conditional statements.

in plain english:

if user is logged in { present the normal template }
else {
present a minimal template which only contains the login module
and additionallly if the visitor requests the lost password or registration page let them see that too }

and the code:

Code: Select all

<body>
<!-- Check to see if visitor is logged in -->
<?php if ( $my->id) {?>

<!-- IS logged in so deliver normal template

Your normal template HTML here -->

<?php }
else {?>
<!--  Visitor NOT logged in so deliver the login page

HTML for the minimal login page  - I have made it REALLY minimal for this example -->

<div>

<!-- here we load a module position for the login module
In the admin panel only assign the login module to this position -->

       <?php mosLoadModules ( 'user5', -2 ); ?>

</div>

<!-- here we check if the visitor needs the Registration page/forgotten password page -->
    <?php if ($option == 'com_registration'){ ?>

<!-- YES visitor wants registration or forgotten password page so include mainbody content -->

    <div>
        <?php include ("mainbody.php"); ?>
    </div>

<?php } ?>
<!-- end of needs registration/forgotten password check -->



<?php } ?>


</body>
I hope someone finds this useful  ;)

IMPORTANT NOTE:
If you are doing this for security - you should either remove all other templates from your site OR implement this modification on ALL templates. This is because the user can actually CHANGE THE TEMPLATE therefore bypassing this modification!!
Last edited by dhuelsmann on Wed Nov 15, 2006 5:16 pm, edited 1 time in total.
Do you want the answer to be as vague as your question?

vavroom

Re: Force login before access to site - my solution

Post by vavroom » Thu Aug 25, 2005 1:02 am

Interesting solution toubkal.  I know I've seen many people ask for something like that in the past at the "old" forum.  I've never seen a need for it, but that's cool.  I could actually see a use where you could deliever a different template/sections/categories depending on the login used to get in. 

With better ACL, that could turn out to be a very powerful solution :)

IcedGoblin
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Tue Oct 18, 2005 10:46 pm

Re: Force login before access to site - my solution

Post by IcedGoblin » Tue Oct 18, 2005 10:51 pm

Hi toubkal,

You are a genius for finding a solution to this problem, I am surprised that not many more people are looking for this solution!!

I must confess however, I am a newbie, and would need a little help in implementing this correctly....

Is it my default template index.php that I need to edit, and where abouts do I need to place the php code?

Your help would be greatly appreciated!

User avatar
toubkal
Joomla! Hero
Joomla! Hero
Posts: 2860
Joined: Thu Aug 18, 2005 4:35 pm
Location: Cheshire, England
Contact:

Re: Force login before access to site - my solution

Post by toubkal » Tue Oct 18, 2005 11:20 pm

I cannot be sure for all templates but basically if you take your current template index.php

(make a backup of it)

everything that is currently within your template's   tags needs to go within the code I posted above, where it says: Your normal template HTML here -->

Maybe it is easiest to post an example:

If this was your template's index.php

Code: Select all

<?php
/**
* template_name - Mambo 4.5.1 template
* @version 4.5.1
* @copyright ( - All Rights Reserved
* @license licensce info here
*/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
$iso = split( '=', _ISO );
echo '<?xml version="1.0" encoding="'. $iso[1] .'"?' .'>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php if ( $my->id ) initEditor(); ?>
    <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO; ?>" />
    <?php mosShowHead(); ?>
    <?php echo "<meta name=\"author\" content=\"www.site.co.uk\" />" ?>
   <?php echo "<link rel=\"stylesheet\" href=\"$GLOBALS[mosConfig_live_site]/templates/$GLOBALS[cur_template]/css/template_css.css\" type=\"text/css\"/>" ; ?>
   <?php echo "<link rel=\"shortcut icon\" href=\"$GLOBALS[mosConfig_live_site]/images/favicon.ico\" />" ; ?>
</head>
<body>

<div id="container">
<div id="page">
    <div id="topnav">
        <?php mosLoadModules ( 'user1', -1 ); ?>
    </div>
    <div id="modcol">
        <?php mosLoadModules ( 'left', -2 ); ?>
    </div>
    <div id="content">
        <?php mosLoadModules ( 'top', -2 ); ?>
        <?php include ("mainbody.php"); ?>
        <?php mosLoadModules ( 'footer', -2 ); ?>
    </div>
</div>
</div>

</body>
</html>
the new version would look like:

Code: Select all

<?php
/**
* template_name - Mambo 4.5.1 template
* @version 4.5.1
* @copyright ( - All Rights Reserved
* @license licensce info here
*/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
$iso = split( '=', _ISO );
echo '<?xml version="1.0" encoding="'. $iso[1] .'"?' .'>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php if ( $my->id ) initEditor(); ?>
    <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO; ?>" />
    <?php mosShowHead(); ?>
    <?php echo "<meta name=\"author\" content=\"www.site.co.uk\" />" ?>
   <?php echo "<link rel=\"stylesheet\" href=\"$GLOBALS[mosConfig_live_site]/templates/$GLOBALS[cur_template]/css/template_css.css\" type=\"text/css\"/>" ; ?>
   <?php echo "<link rel=\"shortcut icon\" href=\"$GLOBALS[mosConfig_live_site]/images/favicon.ico\" />" ; ?>
</head>
<body>

<!-- Check to see if visitor is logged in -->
<?php if ( $my->id) {?>

<!-- IS logged in so deliver normal template

Your normal template HTML here -->

<div id="container">
<div id="page">
    <div id="topnav">
        <?php mosLoadModules ( 'user1', -1 ); ?>
    </div>
    <div id="modcol">
        <?php mosLoadModules ( 'left', -2 ); ?>
    </div>
    <div id="content">
        <?php mosLoadModules ( 'top', -2 ); ?>
        <?php include ("mainbody.php"); ?>
        <?php mosLoadModules ( 'footer', -2 ); ?>
    </div>
</div>
</div>


<?php }
else {?>
<!--  Visitor NOT logged in so deliver the login page

HTML for the minimal login page  - I have made it REALLY minimal for this example -->

<div>

<!-- here we load a module position for the login module
In the admin panel only assign the login module to this position -->

       <?php mosLoadModules ( 'user5', -2 ); ?>

</div>

<!-- here we check if the visitor needs the Registration page/forgotten password page -->
    <?php if ($option == 'com_registration'){ ?>

<!-- YES visitor wants registration or forgotten password page so include mainbody content -->

    <div>
        <?php include ("mainbody.php"); ?>
    </div>

<?php } ?>
<!-- end of needs registration/forgotten password check -->



<?php } ?>

</body>
</html>
Do you want the answer to be as vague as your question?

User avatar
toubkal
Joomla! Hero
Joomla! Hero
Posts: 2860
Joined: Thu Aug 18, 2005 4:35 pm
Location: Cheshire, England
Contact:

Re: Force login before access to site - my solution

Post by toubkal » Wed Oct 19, 2005 7:26 am

IcedGoblin I will answer your pm regarding the layout of the login page here so other can see too.

You can create whatever layout you require. Think of the part after the



as like a second template index just for the login form (and when required, the registration form) which uses the same css file for the styling.

Here I have separated the two key parts to be placed in your layout:

This is the bit to load the login module position

Code: Select all

<div>

<!-- here we load a module position for the login module
In the admin panel only assign the login module to this position -->

       <?php mosLoadModules ( 'user5', -2 ); ?>

</div>
This is the part that delivers the lost password/registration form:

Code: Select all

<!-- here we check if the visitor needs the Registration page/forgotten password page -->
    <?php if ($option == 'com_registration'){ ?>

<!-- YES visitor wants registration or forgotten password page so include mainbody content -->

    <div>
        <?php include ("mainbody.php"); ?>
    </div>

<?php } ?>
<!-- end of needs registration/forgotten password check -->
You can use css to style the login area, using the same style sheet as for the main template if you wish.
Do you want the answer to be as vague as your question?

wolfcreek
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Tue Aug 23, 2005 3:42 am
Location: Wolfforth, TX
Contact:

Re: Force login before access to site - my solution

Post by wolfcreek » Fri Oct 28, 2005 12:00 pm

Also, it needs to be pointed out that anyone using Community Builder or CBE must replace "com_registration" with "com_comprofiler" or else you won't be able to add people through your CB user manager.  It's a problem if you require mail verification or profile approval.

Just a point of clarification here.

BTW, it's a great addition Toubkal.  I utilize it on my sites and will be working it into a couple of my clients.

Wolf.
I can't sign this, cuz my electronic pen is out of ink.
Wolf Creek Idea Group
http://www.wolfcreekideagroup.com

warmac
Joomla! Intern
Joomla! Intern
Posts: 93
Joined: Wed Oct 12, 2005 10:16 pm

Re: Force login before access to site - my solution

Post by warmac » Sun Oct 30, 2005 12:58 am

wolfcreek wrote: Also, it needs to be pointed out that anyone using Community Builder or CBE must replace "com_registration" with "com_comprofiler" or else you won't be able to add people through your CB user manager.  It's a problem if you require mail verification or profile approval.

Just a point of clarification here.

BTW, it's a great addition Toubkal.  I utilize it on my sites and will be working it into a couple of my clients.

Wolf.
what do you mean be replacing com_registration with com_comprofiler, how do we do that ?

by deleting com_reg folder ? or through the admin panel somewhere

User avatar
dmcole
Joomla! Intern
Joomla! Intern
Posts: 92
Joined: Wed Aug 17, 2005 10:50 pm

Re: Force login before access to site - my solution

Post by dmcole » Sun Oct 30, 2005 1:05 am

warmac wrote: what do you mean be replacing com_registration with com_comprofiler, how do we do that ?

by deleting com_reg folder ? or through the admin panel somewhere
Scroll back up and find this line in his code:

Code: Select all

<!-- here we check if the visitor needs the Registration page/forgotten password page -->
    <?php if ($option == 'com_registration'){ ?>
if you're using CB, that line should read ...

Code: Select all

<!-- here we check if the visitor needs the Registration page/forgotten password page -->
    <?php if ($option == 'com_profiler'){ ?>
\dmc

warmac
Joomla! Intern
Joomla! Intern
Posts: 93
Joined: Wed Oct 12, 2005 10:16 pm

Re: Force login before access to site - my solution

Post by warmac » Sun Oct 30, 2005 1:28 am

ok I think I understand according to the above example, but when I tried to put that into my index the entire page goes blank

I've never used user5 position before according to the positioning user5 is at the bottom of the page
Last edited by warmac on Sun Oct 30, 2005 1:46 am, edited 1 time in total.

warmac
Joomla! Intern
Joomla! Intern
Posts: 93
Joined: Wed Oct 12, 2005 10:16 pm

Re: Force login before access to site - my solution

Post by warmac » Sun Oct 30, 2005 2:07 am

all this time trying to get the community builder to work with Joomla and I find out that the version doesn't work with Joomla but supposely the next version will.  Guess I'll unstaill it for now and wait

wolfcreek
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Tue Aug 23, 2005 3:42 am
Location: Wolfforth, TX
Contact:

Re: Force login before access to site - my solution

Post by wolfcreek » Mon Oct 31, 2005 11:46 am

warmac wrote: ok I think I understand according to the above example, but when I tried to put that into my index the entire page goes blank

I've never used user5 position before according to the positioning user5 is at the bottom of the page
Warmac, you can use any position you want, but you just need to make sure that it is a dedicated position with the login issue specifically in place.  I haven't found any trouble utilizing the hack.
warmac wrote: all this time trying to get the community builder to work with Joomla and I find out that the version doesn't work with Joomla but supposely the next version will.  Guess I'll unstaill it for now and wait
I'm using it...have you hacked the comprofiler.php file?  You can access the hack at mambojoe.com or go to Mambome.com and find the CBE component, and try their variations.

I'm anxious for next releases, but haven't got the time to wait, as I have two sites already utilizing these components on a large scale, and several other clients in the process of incorporating community aspects, too.

Wolf.
I can't sign this, cuz my electronic pen is out of ink.
Wolf Creek Idea Group
http://www.wolfcreekideagroup.com

User avatar
keliix06
Joomla! Ace
Joomla! Ace
Posts: 1022
Joined: Wed Aug 17, 2005 11:46 pm
Location: Minneapolis, MN
Contact:

Re: Force login before access to site - my solution

Post by keliix06 » Mon Oct 31, 2005 3:20 pm

Couldn't you make the first page in the main menu the login component then just assign a minimal template to that menu item? Then just set all of your content to only be accessable by registered users?
Doyle Lewis
BuyHTTP Internet Services
http://www.buyhttp.com/joomla_hosting.html - No Overselling Guarantee. Your Joomla site, faster.
http://www.joomlademo.com - 30 day free trial of Joomla

wolfcreek
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Tue Aug 23, 2005 3:42 am
Location: Wolfforth, TX
Contact:

Re: Force login before access to site - my solution

Post by wolfcreek » Tue Nov 01, 2005 12:10 pm

keliix06 wrote: Couldn't you make the first page in the main menu the login component then just assign a minimal template to that menu item? Then just set all of your content to only be accessable by registered users?
That's usually how it's done, but this hack allows you to verify memberships/registered users by assigning a specific template to certain areas.  It's also another way to force registration instead of just displaying "You have to be a registered user to access this page" or "You are not authorized to view this".  Instead of a DENIED, you give them the alternative to register.  I find it keeps surfers in house and empowers them to get to the information. It's allowed my site to increase in size, instead of deterring the visitor to just close the window or decide it's not worth it.

It's all a matter of how you want to approach things, and whether or not you feel it's necessary.  For those of using Community Builder and some sort of Account payment system, it helps to drive sales, and/or develop mailing lists for future info and releases.

Just my opinion.

Wolf.
I can't sign this, cuz my electronic pen is out of ink.
Wolf Creek Idea Group
http://www.wolfcreekideagroup.com

warmac
Joomla! Intern
Joomla! Intern
Posts: 93
Joined: Wed Oct 12, 2005 10:16 pm

Re: Force login before access to site - my solution

Post by warmac » Tue Nov 01, 2005 4:49 pm

I find it keeps surfers in house and empowers them to get to the information. It's allowed my site to increase in size, instead of deterring the visitor to just close the window or decide it's not worth it.
That's just a more pretty way of keeping visitors on strings to bait them ( I believe there's a term for this form of manipulation)  :laugh:

It wouldn't inspire me to register, I'd just close the window ;D

I like (access denied) it's simple and very clear - I think the visitor has the right to choose if they want to participate in a site or not without having to be baited.  Since so many sites these days use some form of registration/list entrapment tactics alot of visitors tend to not want to engage in it unless its' something they really want to do.

thanks to programs like (bugmenot) you can access most things without ever having to register, it spits out a username/password for you and you can just read the content and get out.

otacon7
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Tue Dec 13, 2005 12:36 am

Re: Force login before access to site - my solution

Post by otacon7 » Fri Dec 30, 2005 10:55 am

What if, instead of including the alternate template within the same file, you want to make it so if the user logs in, then it automatically switches to another templete. How would you do this??

mili
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Sun Feb 19, 2006 2:35 am

Re: Force login before access to site - my solution

Post by mili » Tue Mar 28, 2006 3:51 pm

This is neat.

Eike has another piece of code which redirects http sessions coming from certain IP addresses to the login page or any other page

I still haven't got Eike's code to work on my setup but would be nice if these two features were merged into one

Thoughts?

-Niko

Requiem
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Sep 15, 2005 3:53 am

Re: Force login before access to site - my solution

Post by Requiem » Tue Mar 28, 2006 5:35 pm

Unbelievably helpful thread!

I'm a newbie who's been trying to figure this out for a while. Very nice solution.

- Jon G

mili
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Sun Feb 19, 2006 2:35 am

Re: Force login before access to site - my solution

Post by mili » Tue Mar 28, 2006 6:34 pm

Hey guys

Am strugling to get this working but my template won't load at all after following instructions above

Can someone help modifying it? Thanks Niko

This is my temlate index.php file:

#################################################################################

';
?>



id ) {
initEditor();
}
?>


/templates/dwd_hostalavista/css/template_css.css" />




function addBookmark(title,url) {

  var msg_netscape = "NetScape message";
  var msg_opera    = "This function does not work with this version of Opera.  Please bookmark us manually.";
  var msg_other    = "Your browser does not support automatic bookmarks.  Please bookmark us manually.";
  var agt          = navigator.userAgent.toLowerCase();


  if (agt.indexOf("opera") != -1)
  {
    if (window.opera && window.print)
    {
      return true;
    } else
    {
      alert(msg_other);
    }
  }   
  else if (agt.indexOf("firefox") != -1) window.sidebar.addPanel(title,url,"");
  else if ((agt.indexOf("msie") != -1) && (parseInt(navigator.appVersion) >=4)) window.external.AddFavorite(url,title);
  else if (agt.indexOf("netscape") != -1) window.sidebar.addPanel(title,url,"")       
  else if (window.sidebar && window.sidebar.addPanel) window.sidebar.addPanel(title,url,"");
  else alert(msg_other);
 
}





 
   
       
     

     
 
 
    /templates/dwd_hostalavista/images/hosta1.jpg" class="title"> 
     
 


 
   
     
       
          /templates/dwd_hostalavista/images/home_noir.gif" border="0" align="absmiddle" alt="Home"/>  /templates/dwd_hostalavista/images/dotvertical.gif" width="9" height="16" align="absmiddle" />  /templates/dwd_hostalavista/images/print_noir.gif" border="0" align="absbottom" alt="Print"/>  /templates/dwd_hostalavista/images/dotvertical.gif" width="9" height="16" align="absmiddle" />  getPageTitle(); ?>',top.location.href)">/templates/dwd_hostalavista/images/bookmark_noir.gif" border="0" align="absbottom" alt="Bookmark"/>
       
       
         
           
             
               
                 
               
             
           
         
       
       
          /templates/dwd_hostalavista/images/hosta2.jpg" style="background-repeat:no-repeat">/templates/dwd_hostalavista/images/pixel.png" width="1" height="42" />
       
     
     
       
         
             
       
     
     
       
         
             
         
       
     
     
       
         
           
       
     
   
     
        /templates/dwd_hostalavista/images/pixel.png" width="1" height="5" />
     
     
        /templates/dwd_hostalavista/images/dot.gif">/templates/dwd_hostalavista/images/pixel.png" width="1" height="3" />
       
 
     
         
     
 
   
     
       
         
           
             
           
         
           
             
               
               
             
           
           
             
               
             
         

         
           
             
                 
 
           

         
 
       
     
 
 
     
     
         


 
    /templates/dwd_hostalavista/images/dot.gif">/templates/dwd_hostalavista/images/pixel.png" width="1" height="3" />
 
 
   
     
          /templates/dwd_hostalavista/images/home_vert.gif" width="12" height="10" align="bottom" /> Home /templates/dwd_hostalavista/images/dotvertical.gif" width="9" height="16" align="absmiddle" /> /templates/dwd_hostalavista/images/print_vert.gif" width="15" height="16" align="absbottom" />Print /templates/dwd_hostalavista/images/dotvertical.gif" width="9" height="16" align="absmiddle" /> @ Contact /templates/dwd_hostalavista/images/dotvertical.gif" width="9" height="16" align="absmiddle" /> /templates/dwd_hostalavista/images/top_vert.gif" width="14" height="16" align="absbottom" />Top

             

       
     
   
 




#################################################################################

houbahop
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 105
Joined: Wed Dec 14, 2005 10:39 pm

Re: Force login before access to site - my solution

Post by houbahop » Tue Mar 28, 2006 7:05 pm

Isn't it possible to joomla to make the menu items and the content to be visible for registered users only???

room58
Joomla! Intern
Joomla! Intern
Posts: 65
Joined: Wed Apr 19, 2006 3:18 pm

Re: Force login before access to site - my solution

Post by room58 » Fri Jun 09, 2006 1:56 pm

I have implemented this method but have found only one drawback. If the users session expires whilst broswing the site (on say a content page where the URL is (Http://www.domain.com/index.php?option= ... &Itemid=27). and they hit Refresh (CTRL F5), they get the login screen but with no modules loaded. If you return to the site root, it's fine, just when you have querystring params.

Why would this happen?

redlokki
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Thu Jan 19, 2006 3:21 am

Re: Force login before access to site - my solution

Post by redlokki » Mon Oct 30, 2006 7:22 pm

I'm looking for something similar, but I'd like to isolate the registration portion in a JS popup or, better, handle the form through Flash:

http://forum.joomla.org/index.php/topic,108904.0.html

I tried creating a new, blank document with the appropriate calls, but the core security disallows direct access. I am puzzling out how to simply send the relevant form info directly from Flash without worrying about creating a mini PHP registration page, but I think that will encounter the same problems.

Any thoughts on how to get there from here?

wsecomp
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Sat Sep 09, 2006 5:24 am

Re: Force login before access to site - my solution

Post by wsecomp » Sun Nov 12, 2006 3:55 am

I have a similar question...

Instead of using a completely different template, is it possible to force a page upon a logged-in user's return?

I have set the redirect in CB, but upon returning to the site, users still see the site's intro screen.

Could I force something like:

If not logged in, show contentID=## else show mosContent (or whatever it's called)?  ???

User avatar
toubkal
Joomla! Hero
Joomla! Hero
Posts: 2860
Joined: Thu Aug 18, 2005 4:35 pm
Location: Cheshire, England
Contact:

Re: Force login before access to site - my solution

Post by toubkal » Mon Nov 13, 2006 9:26 am

If you are referring to for e.g. a front page welcome message, I usually use a module position which is hidden for logged in users

You can then create a welcome message in the module manager ( modules > site modules > new )
e.g. Here I create a module position 'top' only for those NOT logged in
id ) {?>
       
       
and here in a simpler form ( without jumping in and out of php for the html div etc )
id ) {
        mosLoadModules ( 'top', -2 );
        } ?>
Do you want the answer to be as vague as your question?

thedude
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Tue Feb 28, 2006 12:12 am

Re: [RESOURCE]Force login before access to site - my solution

Post by thedude » Wed Jan 24, 2007 7:31 pm

This is probably a dumb question for experienced users so please forgive me for being a noob!

What is the -1 or -2 in the load module function and what does it do?

User avatar
toubkal
Joomla! Hero
Joomla! Hero
Posts: 2860
Joined: Thu Aug 18, 2005 4:35 pm
Location: Cheshire, England
Contact:

Re: [RESOURCE]Force login before access to site - my solution

Post by toubkal » Wed Jan 24, 2007 8:24 pm

it specifies the type of container that the module will be output within e.g. div / table / nested divs / raw

see
http://help.joomla.org/content/view/33/125/
Do you want the answer to be as vague as your question?

thedude
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Tue Feb 28, 2006 12:12 am

Re: [RESOURCE]Force login before access to site - my solution

Post by thedude » Fri Jan 26, 2007 12:37 am

Thanks so much for the reply toubkal.

Here is another question and I am trying to make it very simple for myself. Would this chunck of code work putting two templates on one page?

Code: Select all

<?php if ( $my->id) {?>
code for one template
<?php }
else {?>
code for the second template
<?php } ?>
Is it missing anything?

Thanks

Cylindric
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Wed Jul 26, 2006 11:28 am

Re: [RESOURCE]Force login before access to site - my solution

Post by Cylindric » Fri Jan 26, 2007 11:56 am

Wow, thanks toubkal!

Uncanny timing, because I was just looking for something to do this for an intranet site, where we want the whole thing to be member-only!

Thanks.

User avatar
toubkal
Joomla! Hero
Joomla! Hero
Posts: 2860
Joined: Thu Aug 18, 2005 4:35 pm
Location: Cheshire, England
Contact:

Re: [RESOURCE]Force login before access to site - my solution

Post by toubkal » Sat Jan 27, 2007 9:16 am

thedude wrote: Thanks so much for the reply toubkal.

Here is another question and I am trying to make it very simple for myself. Would this chunck of code work putting two templates on one page?

Code: Select all

<?php if ( $my->id) {?>
code for one template
<?php }
else {?>
code for the second template
<?php } ?>
Is it missing anything?

Thanks
Yes, you can do that. You may be able to use just 1 css stylesheet for both but if you wanted to use 2 diferent ones you can just place more (or all) of the template code within the IF / ELSE statement so that a different stylesheet is referenced for each situation.
Do you want the answer to be as vague as your question?

RakiuraSkies
Joomla! Intern
Joomla! Intern
Posts: 83
Joined: Thu Oct 12, 2006 8:18 am

WoooHooo!!!

Post by RakiuraSkies » Sun Jan 28, 2007 12:32 am

This is awesome!  I don't know how long I have looked, how many searches made, tried so many different things to achieve JUST THIS!  Thank you!  :pop

Now... can i mod the 'very minimal template' to something that'll make people want to visit my site!!!

RakiuraSkies
Joomla! Intern
Joomla! Intern
Posts: 83
Joined: Thu Oct 12, 2006 8:18 am

Re: [RESOURCE]Force login before access to site - my solution

Post by RakiuraSkies » Sun Jan 28, 2007 12:52 am

toubkal wrote: If you are referring to for e.g. a front page welcome message, I usually use a module position which is hidden for logged in users

You can then create a welcome message in the module manager ( modules > site modules > new )
e.g. Here I create a module position 'top' only for those NOT logged in
id ) {?>
       
       
and here in a simpler form ( without jumping in and out of php for the html div etc )
id ) {
        mosLoadModules ( 'top', -2 );
        } ?>
OK, I think what I want to do is add a welcome message to the new login page.  A few questions though...
  • Which module are you referring to?
  • How do I make the module hidden for logged-in users?
  • In which file does the code modification shown go?
  • In what position within the file should the code be placed?
I think that's about it -for the now :)

Again thanks Toubkal, so far I really like the way this is shaping up!


Locked

Return to “General Questions - 1.0.x”