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
    You can’t count on that method working in the future and it might not work in all cases. I would use the recommended public function:

    public function hasSessionContext($context) {
            $hasContext= false;
            if ($this->getSessionContexts()) {
                $contextTokens= array ();
                if (is_array($context)) {
                    foreach ($context as $ctx) {
                        $contextTokens[$ctx]= $this->get('id');
                    }
                }
                elseif (is_string($context)) {
                    $contextTokens[$context]= $this->get('id');
                }
                $hasContext= (count(array_intersect_assoc($contextTokens, $this->sessionContexts)) == count($contextTokens));
            }
            return $hasContext;
        }
      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
      • 22980
      • 84 Posts
      Is there a way to ensure that the user has been logged in from a custom and independent/custon php script?

      Here’s the session data being passed in:

          [__utmz] => 242157571.1280079143.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
          [modx_setup_language] => en
          [ys-modx-tree-action] => s:/n_root_0/n_namespace_brothers/n_action_76
          [ys-modx-resource-tree] => s:/root/web_0/web_22
          [ys-modx-leftbar-state] => o:activeTab=n%3A1
          [ys-modx-element-tree] => s:/root/n_type_template/n_template_element_1_0
          [PHPSESSID] => btma08n15j1c1kj20vi6kkekg0
          [__utma] => 242157571.1284413755.1280079143.1282627617.1282655759.20
          [__utmc] => 242157571
          [__utmb] => 242157571.15.10.1282655759


      I’m creating a /proc folder with a custom .php file, independent of Modx but still managing site data. I do this to attempt to keep things simple. I figure I should ask -- Is there a good & advantageous way to integrate this cleanly with MODx?

      Thanks
        • 3749
        • 24,544 Posts
        I think you could add this to the top of the code and use hasSessionContext as described above:

        define('MODX_CORE_PATH', 'c:/xampp/htdocs/addons/core/');
        define('MODX_CONFIG_KEY', 'config');
        require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
        $modx= new modX();
        $modx->initialize('web'); // use the name of the front-end context
        


        I’m not sure if it would work. Initializing the context, might log the person out.
          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