We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5340
    • 1,624 Posts
    Hi,

    Why would the following code(plugin)


    $e = &$modx->Event;
    
    if( $e->name == "OnWebPageInit"){
        
        if( isset($_SESSION['mgrValidated']) ){
         
            $url = $_SERVER['REQUEST_URI'];
            $secureserver   = "https://mysite.com";
        
            $modx->sendRedirect($secureserver.$url);
        }
    
    }




    Make firefox say

    Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
    *   This problem can sometimes be caused by disabling or refusing to accept
              cookies.


    Make safari say
    Too many redirects occurred trying to open “https://mysite.com/”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.


    I’m trying to secure the entire website using a plugin. This plugin will run in some cases so a htaccess solution will not work.

    Thank You
      • 5340
      • 1,624 Posts
      I moved the above code to the SSL plugin and I have the same problem. For some reason a loop is happening.

      I manage to log the call and I get 17 logs when accessing a page

      if( isset($_SESSION['mgrValidated']) ){
              
              $modx->logEvent(29, 1, $secureserver.$url , $source= 'SSL');
              $modx->sendRedirect($secureserver.$url);
              
          }else{
          
              if($encryption && !$ssl) {
                  
                  // if SSL off and we are about to access a secure page then redirect
                  $modx->sendRedirect($secureserver.$url);
                  
              } else if ($ssl && !$encryption) {
                  
                  // if SSL is on and we are about to acccess an unsecure page then redirect
                  $modx->sendRedirect($insecureserver.$url);
                  
              }
              
          }



      $modx->logEvent(29, 1, $secureserver.$url , $source= ’SSL’);
      is called 17 times. Not sure what could trigger the loop. It only happens if $_SESSION[’mgrValidated’] is set.

      I will do some more tests. Meanwhile, any ideas are welcomed
        • 5340
        • 1,624 Posts
        Seems that $modx->sendRedirect($secureserver.$url); triggers the call of OnWebPageInit event again and again
        Any ideas why? Can I set up a global variable or something?


          • 5340
          • 1,624 Posts
          I used the code bellow in the SSL plugin

          Because the manager was using a secure connection QM+ was not working properly. Editing a page with QM+ was not possible as it would request a secure page and that would be detected a crosssite attack.

          //manager logged in 
          if( isset($_SESSION['mgrValidated']) ){
          
              if($ssl){
                  //ntd - ssl activated
              }else{
                  //activate ssl
                  $modx->sendRedirect($secureserver.$url);
              }
          
          
          }else{
          
              if($ssl){
              
                  if($encryption){
                      //ntd - ssl activated
                  }else{
                      //deactivate ssl
                      $modx->sendRedirect($insecureserver.$url);
                  }
              
              }else{
                  
                  if($encryption){
                      $modx->sendRedirect($secureserver.$url);
                  }else{
                      //ntd - regular page
                  }
              
              }
              
          }