We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9439
    • 90 Posts
    Hi, I’ve configured wlpe to protect an entire site and it seems to work well enough. So if someone tries to access the site from a bookmark or simply typing in a url other than the home (login) page, personalize detects if they’re logged in or not and if not displays the login form on the page they’re trying to view. So far so good. But instead of displaying the login form, I want to divert anyone coming in to the site who’s not logged in to the home page, irrespective of what page they try to enter the site from, so that they get to the proper login page. Can that be done?

    thanks

    David Heriot
      David Heriot
      pfsmedia
      • 4041
      • 788 Posts
      Give this snippet a try, it should work fine for that application:

      <?php
      /* CheckLogin
         - redirects visitors to site start page if not logged in as a webuser
         usage: create a new snipet with this code
                add the snippet call to the top of your template
      */
      // set the page you want to redirect to (ID)
      // default is site start
      $homepageid  = $modx->config['site_start'];
      
      // set the ID of your login page here
      $loginpageid ='XX';
      
      $currentid   = $modx->documentIdentifier;
      
      // we don't want them to redirect if this page is the home page or the login page
      if($currentid != $homepageid || $currentid != $loginpageid){
          if($_SESSION[webShortname] ==''){   
             return $modx->sendRedirect($homepageid);
          }
      }
      ?>
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 9439
        • 90 Posts
        Breezer, absolutely brilliant. Thank you very much.

        (I’m a wee bit perplexed though that I had to ask - surely I couldn’t have been the first to need this function, unless of course others have had, and simply scribbled out a quick snippet ala breezer wink)

        David Heriot
          David Heriot
          pfsmedia