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
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);
}
}
?>