We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    There's a good chance that the site sets a cookie. If so, you may be able to check it.

    This should show any cookies in the MODX error log:

    $modx->log(modX::LOG_LEVEL_ERROR, 'COOKIES: 
    ' . print_r($_COOKIES, true));


    Put it just above the if($authenticated) line. [ed. note: BobRay last edited this post 9 years, 9 months ago.]
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 38357
      • 178 Posts
      Quote from: BobRay at Dec 07, 2016, 11:48 PM
      There's a good chance that the site sets a cookie. If so, you may be able to check it.

      This should show any cookies in the MODX error log:

      $modx->log(modX::LOG_LEVEL_ERROR, 'COOKIES: 
      ' . print_r($_COOKIES, true);


      Put it just above the if($authenticated) line.
      No - that stops the script executing and the user is not created so no login and no cookie - nothing in the error log.
      The script logs in to the remote site and loads the remote page into an iframe.
       <form name="myclubLogin" id="myclubLogin" method="post" action="url_to_log_in_to_remote_server" target="myClub"> 
        
                  <fieldset class="loginLoginFieldset" >
        
                      <input id="action" type="hidden" name="action" value="login" /> 
                      <input class="loginUsername" type="hidden" name="user" id="user"   />
                        
                      <input type="hidden" name="password"  />
                      <input id="action" type="hidden" name="action" value="password" /> 
        
                      <input class="loginLoginValue" type="hidden" name="service" value="login" />
                      <span class="loginLoginButton">
                      <input id="myLogin" name="myLogin" type="submit" value="[[+actionMsg]]" style="float: right;"/>
                      </span>
        
                  </fieldset>
              </form> 
        
      <div> 
      <iframe id="myClub" name="myClub" style="width:0; height:0; border:0; border: none;"></iframe>
      </div>

      As the remote page is called into an iframe I am beginning to wonder if I can use the 'onload' event in the iframe in some way to create a session variable to be retrieved by the plugin script and be used in the if ..else? Can sessions be activated like this from a chunk?
        • 3749
        • 24,544 Posts
        Sorry, the second line here had a missing final ')'. That's what was stopping things. It should be (fixed above):

        $modx->log(modX::LOG_LEVEL_ERROR, 'COOKIES:
        ' . print_r($_COOKIES, true));
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 38357
          • 178 Posts
          Thanks Bob,
          Yes - this shows the cookies in the error log - but not all.
          ( print_r($_COOKIES, true));
          doesn't work but
           print_r($_COOKIE, true));
          does ).
          It shows cookies set by Modx but not the cookies set by the remote site - I suspect because the page is in an Iframe? I know that the remote page sets a cookie JSESSIONID when the user is logged on but it doesn't show up.
            • 3749
            • 24,544 Posts
            I'm not sure the iFrame is the issue. The remote login site's cookies are stored on the users local computer, in a section for cookies from that remote domain. I should have realized your script is running in a different domain, so the browser isn't going to let you have them.

            I don't suppose the remote login site has OAuth capability? That would be ideal for what you're doing. The OAuth server is where the user logs in, and other servers can query it for the results.

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 38357
              • 178 Posts

              Thanks again Bob,
              Quote from: BobRay at Dec 10, 2016, 01:27 PM
              I'm not sure the iFrame is the issue. The remote login site's cookies are stored on the users local computer, in a section for cookies from that remote domain. I should have realized your script is running in a different domain, so the browser isn't going to let you have them.

              I don't suppose the remote login site has OAuth capability? That would be ideal for what you're doing. The OAuth server is where the user logs in, and other servers can query it for the results.

              No OAuth available unfortunately.
              It all seems too hard :-( If I could somehow get the URL of the remote page that is loaded into the iframe after login I would be able to compare it with what it should be and set a variable to say 'Yes' logged in correctly or 'No' the expected URL is not loaded in the iframe. It seems ridiculous that I can't get some evidence that the correct page has been loaded into the iframe.
                • 3749
                • 24,544 Posts
                I don't think this will work, but it's worth a try:

                Put this tag in the iframe:

                [[!GetUrl]]

                Then create a snippet called GetUrl with this code:

                $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
                <?php
                $msg = 'REQUEST_URI: ' .  $_SERVER["REQUEST_URI"] .
                    'HOST: ' . $_SERVER["HTTP_HOST"] .
                    'SERVER_NAME: ' . $_SERVER["SERVER_NAME"] .
                    'REFERER" ' . $_SERVER["HTTP_REFERER"] .
                    'URI" ' . $_SERVER["REQUEST_URI"];
                     
                
                $modx->log->(modX::LOG_LEVEL_ERROR, $msg);


                See if anything useful appears in the error log.
                [ed. note: BobRay last edited this post 9 years, 9 months ago.]
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 38357
                  • 178 Posts
                  No - nothing appears in the error log. All I get is what is expected from the plugin:

                  [2016-12-13 13:42:49] (ERROR @ /volume1/web/qpgc/core/cache/includes/elements/modplugin/8.include.cache.php : 61) Event: OnBeforeWebLogin -- Line x of plugin executing
                  [2016-12-13 13:42:49] (ERROR @ /volume1/web/qpgc/core/cache/includes/elements/modplugin/8.include.cache.php : 92) Event: OnWebAuthentication -- Line x of plugin executing
                    • 3749
                    • 24,544 Posts
                    My bad. It should be:

                    [[!GetUrl]]
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 38357
                      • 178 Posts
                      I was going to research that + in a snippet call smiley

                      I also assume that
                      $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
                      <?php
                      $msg = 'REQUEST_URI: ' .  $_SERVER["REQUEST_URI"] .


                      should be
                      <?php
                      $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
                      
                      $msg = 'REQUEST_URI: ' .  $_SERVER["REQUEST_URI"] .


                      Calling the snippet in the body of the iframe breaks the page - it will not load at all - no errors in the error log.

                      It would seem that the only way to do this may be with Curl - which I have never used. http://stackoverflow.com/questions/3008817/login-to-remote-site-with-php-curl [ed. note: bobd72 last edited this post 9 years, 9 months ago.]