We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20682
    • 31 Posts
    I needed to be able to redirect the user to various unauthorized pages depending on the page they were attempting to view.

    With a little prod from opengeek I have a snippet to redirect to a specified id.

    The document access permissions need to be public or the default redirection will still be in place.
    I have added this:
    || isset ($_SESSION['mgrValidated'])
    to the check to allow all managers access to the pages. The redirection will default to the configured unauth page if a redirect id is not set.

    usage:
    [!permission_redirect? &redirectID=`4` &webGroup=`Site Admin,Reg User`!]


    redirectID= id to redirect to
    webGroup= comma separated web user group(s) to have access

    <?php
    $webGroup = isset($webGroup) ? explode(",",$webGroup) : array();
    $redirectID = isset($redirectID) ? $redirectID : $modx->config['unauthorized_page'];
    $test = false;		
    $test = $modx->isMemberOfWebGroup($webGroup);
    if ($test === true || isset ($_SESSION['mgrValidated'])){
    return;
    }else{
    $modx->sendRedirect($modx->makeUrl($redirectID));
    }
    ?>


    Just a little snippet.
    Sheri