We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    I have been working with SESSIONS recently and I have a question... How can I get a session that has been set in an external application on the same server?

    home/modx
    home/ExtApp

    I have my ExtApp setting up a session

    session_start();
    $_SESSION['test']='testing';
    


    If I echo the session it appears to be working and is set in the ExtApp.

    How can I grab this info in modx and use it?  I want to create a plugin that will allow access to a page if the session is found, I got it working fine with cookies but I want the added security of using a session instead.

    I tried the following for my plugin but it doesn’t appear to get the session from the ExtApp. 

    if ( $modx->documentIdentifier == 60){
    echo $_SESSION['test'];
    
    }


    I understand it might not be as straight forward getting a session from another app so if anyone has some pointers on how to get this working with modx that would be great.
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 22303 MODX Staff
      • 10,725 Posts
      The only way to share the same session between multiple applications that manage their own sessions is if they are constructed to work with the same session data in the first place; which of course is rarely the case unless you are using a library of scripts from a common author perhaps. IOW you will most likely have to hack each application to satisfy the session needs of each application sharing it. The more practical solution is generally to use plugins in each application to resolve the SSO by having it make a request to the other application to see if a user is authenticated, or has a specific piece of session data (assuming the application allows such a technique through a web service or other API). You could also use an external message queue or database table to communicate this kind of data between the applications.
        • 25551 ☆ A M B ☆
        • 1,231 Posts
        Thanks OG, that makes sense. For the sake of quickness, is using cookies acceptable to use if such hacking was considered too much work lol.

        I just want a couple pages in modx to be accessible to users if they have signed in to an external app... the external app can create a cookie on login, if it’s present, allow the user access to X YZ pages in modx when they arrive at them. Rather than use sessions which would be the preferred choice, is cookies with a low destroy time alright?
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart