We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41131
    • 5 Posts
    I'm trying to put a login system into modx, for users to gain access to certain parts of a web site once they logged in. The code i have uses Sessions and I'm having nothing but troubles with modx to get the code to work. I'm just wondering if anyone's been down this road and might be able to help me understand how to fix this session problem in modx.


    I'm trying to use this login on my site http://forums.devshed.com/php-faqs-and-stickies-167/how-to-program-a-basic-but-secure-login-system-using-891201.html

    And i Found out yesterday that you can't make a session in modx. But i was wondering if anyone knew a way around this.
    • Is there some reason you don't want to use the Login package? It's very flexible and powerful.

      MODx starts its own session, and by default uses database storage rather than file storage. If you need to access the MODx session, then you need to know the name of the MODx session, and have your script set the session_name and the other session initialization functions before starting the 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
        • 41131
        • 5 Posts
        I'm currently using the Login package and it's working fine but I need to customize certain parts of it and don't understand package script enough to change it. I was hoping to just use php instead so I can make any adjustments needed.

        I need new registered accounts to send a confirmation e-mail to their e-mail, which Login already does perfectly. But I also need it to send a confirmation e-mail to the admins so they can also approve the new account since the membership is not open to the general public.

        I'm trying to set it up the way you're describing. I'm using the following code:

        <?php
        define('MODX_CORE_PATH', '/pathtomodxcore/' );
        require_once ( MODX_CORE_PATH.'model/modx/modx.class.php' );

        // Create an instance of the MODx core
        $modx = new modX();

        // Initialise the core to access the default 'web' context
        $modx->initialize('web');

        And getting the following error:

        Fatal error: Call to a member function get() on a non-object

        Any help would be greatly appreciated since I'm not sure if I'm on the right path or not.

        • Perhaps a posthook would be useful? A posthook is just a snippet that is run after a new user has been registered. Register your posthook with the &postHooks property, and in the snippet send the email to the admin.
            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
            • 41131
            • 5 Posts
            Thanks I'll be reading up on that tonight.
              • 41131
              • 5 Posts
              was I on the right path for creating a session? Beacause i'd prefer to just use this code if possible.
                • 3749
                • 24,544 Posts
                You were on the right track. The error message should give you the line number where the get() is failing. The odds are that it's not a problem with instantiating MODX, but some other object. Usually it's a failed getObject() or getCollection() call with no sanity check.

                That said, I would do it with a Register postHook as Susan suggests. A postHook is just a snippet that you name in the Register snippets &postHooks property (e.g., &postHooks=`EmailAdmin`). In the register postHook snippet you can do this:

                if (isset($hook)) {
                    $userObj = $hook->getValue('register.user');
                    $userProfileObj = $hook->getValue('register.profile');
                    $userEmail = $userProfileObj->get('email');
                    $userName = $userObj->get('username');
                
                    /* send the email here */
                
                }



                  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