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

    I have a problem with modx authorization checking from external php script. I wrote a modx_auth.php which contains:

    <?php
    function isAuthenticatedInModx() {
        require_once dirname(dirname(__FILE__)) . '/config.core.php';
        require_once MODX_CORE_PATH.'model/modx/modx.class.php';
        
        $modx = new modX();
        $modx->initialize('mgr');
        $modx->getService('error','error.modError');
          
        return ($modx->user->hasSessionContext('mgr')) ? true : false;
    }
    


    But when I call isAuthenticatedInModx() function from my external.php file I get nothing, because the function creates a new instance of modX class where I'm not logged in.

    How can I check authorization externally in modx revo? Does have Revo any analogs for Evo's startCMSSession() function?
      • 22303 MODX Staff
      • 10,725 Posts
      There's no one-size-fits-all method to this; this completely depends on your external script. Is it starting it's own session? If so, how? You likely won't be able to access the MODX session from this application's session. The initialize() function calls the non-public method for starting the session, but you will need to either write a custom session handler to utilize the other application's session configuration or find out exactly how the application starts it's session and set the MODX/PHP session configuration options to match. You could write your own session_handler_class and configure that in MODX if necessary.