We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28120
    • 380 Posts
    I've got an application using regular php scripts and I'd like MODX Revolution to have access to the $_SESSION data.

    I've created a test script

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    require_once 'config.core.php';
    require_once MODX_CORE_PATH.'model/modx/modx.class.php';
    $modx = new modX();
    $modx->initialize('web');
    $modx->getService('error', 'error.modError');
    //set the session variable
    $_SESSION['external'] = "hello";
    ?>
    


    On the target server I'm not getting to first base with error

    Catchable fatal error: Argument 1 passed to xPDOObject::load() must be an instance of xPDO, instance of modX given in /var/www/vhosts/domain/httpdocs/core/xpdo/om/xpdoobject.class.php on line 404


    Saw some posts about APC, which this server has, so tried script on a server without APC and there was no error. However I was unable to see my session variable in MODX.

    2 questions then


    1. Is launching MODX from an external script impossible if running APC?
    2. How do I see my session variable. In MODX I had a snippet print_r($_SESSION); which displays loads of stuff but I couldn't see $_SESSION['external'] = "hello". Regardless of APC is my approach flawed?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      MODx has its own sessions, you would need to set your script to use the same session_name and session_save_handler as your MODx installation. Then, as long as they are all on the same domain, you would be using the same session.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 28120
        • 380 Posts
        ok thanks

        How do I find out what these names are?

        Also if it won't run with APC I'm dead in the water anyway.

        Mark
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You can find the site_sessionname in the config.inc.php file; I believe that it's a random string generated on installation. I'm not sure where the session_save_handler is defined; MODx uses a custom database handler. However, in System Settings you can set MODx to use standard PHP session files, which might be useful to make it more easily compatible with your application. You can also set the session name there (in System Settings search for "session").
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 28120
            • 380 Posts
            Oh joy, thank you so much!! You've answered the question I didn't think of asking about getting MODX to use the other session. All now working.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              It's worth taking some time and poking through the whole System Settings. You can find all kinds of interesting possibilities in it.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 22303 MODX Staff
                • 10,725 Posts
                It runs fine with APC. Your stand-alone scripts that use MODX session need to call session_write_close() before exiting however if you want to use the database session handler that MODX uses by default. This is the cause of the original error you posted.
                  • 28120
                  • 380 Posts
                  thanks

                  I'd seen reference to session_write_close() elsewhere and tried that but was still getting the error.