We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26436
    • 19 Posts
    I have a page, let’s call it ’Member Directory’. I want to include this page in the main navigation to draw attention to it, but only want my logged in members to be able to view the file. I have set the Access permission to a particular group (members) and set my configuration to send unauthorized visitors to the login page. Ok all this works fine. However after loggin in successfully I want to return my members to the page that they had initially intended to view, (Member Directory).

    I have noticed in the code for the weblogin it mentions a redirect and calls $_REQUEST[’refurl’]. I assume that this is a cookie that should be set when an unauthorized page is requested and redirected to the login. But this does not appear to work for me.

    I have tried setting up a cookie to hold the current page so that I can pass this page to the WebLogin snippet. But the redirection to the login page occurs before this is set.

    Other attempts to load a variable into the WebLogin snippets parameters have resulted in a ’this is not numeric and cannot be used to makeURL’ error.

    Can anyone help?
      • 10449
      • 956 Posts
      all you really need is:
      [!WebLogin? &loginhomeid=`68`!]
      If your Member Directory id is 68. That should work.

      from the docs:
      # &loginhomeid - (Optional)
      # redirects the user to first authorized page in the list.
      # If no id was specified then the login home page id or
      # the current document id will be used


        • 26436
        • 19 Posts
        Ok, maybe I need to clearify what i needed a bit better. I can get the redirection as you have specified, however, how do i make the &loginhomeid=`64` more dynamic. I would like to have a single login page, but return the user to the page redirected to the login. Simply adding =`64`only works if i want them to always go to the same page. what i really need is &loginhomeid=`[+previouspage+]` but when i do this i get a not numeric cannot makeURL. Also I run into the problem that the page that requires authorization and redirects to the login page does not register as a referring page, and because of that I cant seem to return to that page.
          • 22303 MODX Staff
          • 10,725 Posts
          Yeah, this looks like a change in functionality that was not properly refactored. The $modx->sendUnauthorizedPage() and sendErrorPage() functions used to do redirects and append a refurl parameter to the query string. This functionality was changed to avoid the redirect and properly report the response code on the actual url that was accessed, so there is no longer a way to pass this information in the URL. Instead, it needs to be added to the $_REQUEST superglobal. For now, try opening up manager/includes/document.parser.class.inc.php and find the function sendUnauthorizedPage(). Modify that function to look like this:

          <?php
          
              function sendUnauthorizedPage() {
                  // invoke OnPageUnauthorized event
                  $this->invokeEvent('OnPageUnauthorized');
                  if ($this->config['unauthorized_page']) {
                      $unauthorizedPage= $this->config['unauthorized_page'];
                  } elseif ($this->config['error_page']) {
                      $unauthorizedPage= $this->config['error_page'];
                  } else {
                      $unauthorizedPage= $this->config['site_start'];
                  }
          //        $this->sendRedirect($this->makeUrl($this->config['unauthorized_page'], '', '&refurl=' . urlencode($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'])), 1);
                  $_REQUEST['refurl']= urlencode($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']);
                  $this->sendForward($unauthorizedPage, 'HTTP/1.1 401 Unauthorized');
                  exit();
              }
          
          ?>


          I’m simply adding the line:
          $_REQUEST['refurl']= urlencode($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']);

          right before the call to sendForward() in order to set this variable properly for the weblogin snippet logic. This should re-enable the expected behavior.

          Let me know if that works for you or not.
            • 26436
            • 19 Posts
            Thank you kindly. I dont think i would have thought to work it out there. I did have a slight problem with a 404 because of the %2F character though. However by removing the urlencode portion i was able to get it to function as I had wanted.

            $_REQUEST[’refurl’]= $_SERVER[’PHP_SELF’] . ’?’ . $_SERVER[’QUERY_STRING’];
            instead of
            $_REQUEST[’refurl’]= urlencode($_SERVER[’PHP_SELF’] . ’?’ . $_SERVER[’QUERY_STRING’]);

            Thank you again
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: scott_gb at Jul 18, 2007, 01:59 PM

              I did have a slight problem with a 404 because of the %2F character though. However by removing the urlencode portion i was able to get it to function as I had wanted.

              $_REQUEST[’refurl’]= $_SERVER[’PHP_SELF’] . ’?’ . $_SERVER[’QUERY_STRING’];
              instead of
              $_REQUEST[’refurl’]= urlencode($_SERVER[’PHP_SELF’] . ’?’ . $_SERVER[’QUERY_STRING’]);

              Thank you again

              Ah right, good catch. Since it’s not sending another request, there is no need to encode the URL.