We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8425
    • 159 Posts
    Hi,
    Would this code work if I want to access the current user logged into Modx via an external script?
    require_once '/absolute/path/to/modx/config.core.php';
    require_once MODX_CORE_PATH.'model/modx/modx.class.php';
    $modx = new modX();
    $modx->initialize('web');
    $modx->getService('error','error.modError');
    
    $user = $modx->user->get('username');


    Thanks for your help. [ed. note: eclipseTalk last edited this post 12 years, 3 months ago.]
    • Not if that external script uses sessions. MODX requires the use of sessions and using it in an external application will only work if that app does not require sessions of it's own.
        • 8425
        • 159 Posts
        Thanks for replying.
        I need to get the username in an external IPN php page sent from Paypal to do some custom code processing when a user has made a purchase. I'm not using sessions and I was hoping but using the snippet above to get access to the user running in the current Modx session.
        So it seems that I should be fine. Correct?
        Thanks for your time.
          • 3749
          • 24,544 Posts
          What if more than one user is logged in at the time? It seems your code would have no way of knowing which session to access.

          Could you possibly get the info you need from the PayPal API?

          If only one user could be logged in, you could put a snippet on one of the pages that writes the username to a file, then your external PHP script could just read that file.


          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODx info for everyone: http://bobsguides.com/MODx.html
            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