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

    I'm trying to create a login box for out WHMCS installation. I have tried to get this working the last 4 months, but I'm still stuck.

    But i have finally found out that the problem is somewhere in MODX. I need to get the $_SESSION['uid'] from our whmcs installation. If writing the code in a separate test.php file, it all works great. When trying exactly the same code in modx, i get nothing in return..

    <?php
    require( "dbconnect.php" );
    require( "includes/functions.php" );
    
    if ($_SESSION['uid']) {
        echo "Yay, this works.";
    } else {
    	echo "No, this does not(!) work! :-(";
    }

    In a separate php file: Yay, this works
    In a MODX snippet: No, this does not(!) work! :-(

    Anyone have any idea what I can do to get this session from within modx?
      • 36776
      • 31 Posts
      Let me add that WHMCS is completely crypted, so I cant add anything to the core.
      I have seen alot of posts talking about using the MODX api in the external script, which I cant do in this case..
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        MODX overwrites the session handler so that may be a reason. You can revert MODX to filebased sessions (the PHP default) by emptying the session handler system setting (don't have the exact key ready for you, sorry).
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 36776
          • 31 Posts
          Thanks.
          I found session_handler_class which have the setting modSessionHandler.

          When changing this to empty, the script still does not work, the session is unavailable within modx. Do you have any other ideas? smiley

          I also tried deleting the cache.
            • 22303 MODX Staff
            • 10,725 Posts
            Which application is starting the request? MODX will manage the session if it is not already started when the initialize() method is called. If it is already started, it will stay out of the way for the most part, other than calling session_write_close() before any exit points. But this all depends on what code executes session_start and how that session is configured...
              • 36776
              • 31 Posts
              Hi,

              I'm not quite shure what you mean, but this it how it all is put together:

              I have a customer & billingsystem called WHMCS. This is a separate customerportal in the same domain and folder as MODX.

              In the frontend, I have MODX with a loginbox for WHMCS in the front page.
              If logged in ( $_SESSION['uid']; ) = show some client details
              Else: show the login form.


              This is the code executed when creating the session in WHMCS:
              if ( validateLogin( $username, $password ) )
              {
                  $loginsuccess = true;
                  if ( $rememberme )
                  {
                      setcookie( "WHMCSUID", $_SESSION['uid'], time( ) + 60 * 60 * 24 * 365 );
                      setcookie( "WHMCSPW", $_SESSION['upw'], time( ) + 60 * 60 * 24 * 365 );
                  }
              }
                • 36776
                • 31 Posts
                Anyone have any ideas about this? Why MODX cleans already exsisting sessions, and how I can stop that from happening.
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: tropicaljuice at May 09, 2012, 10:43 AM
                  Anyone have any ideas about this? Why MODX cleans already exsisting sessions, and how I can stop that from happening.
                  MODX does not clean any sessions. If a PHP session is already started when MODX is loaded, it will avoid it's own session initialization and the existing $_SESSION vars should be available. If MODX is starting the session, then you have a different session with MODX that the other application has.
                    • 36776
                    • 31 Posts
                    Ok, so what you are saying is that my script (as i typed above) should work. And if this script don't work with or without the session_handler_class, I should submit a Bug?

                    Thanks
                      • 22303 MODX Staff
                      • 10,725 Posts
                      No, I'm saying if this is running in MODX, it will not have access to the other system's session. That system initializes it's own session in some way and unless you do that before loading MODX, or configure MODX to use the session the other application has created, you will not have access to the other application's session from the MODX session.