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

    I have a problem wihtthe manager loosing my session variables.
    I am trying to use the session created by startCMSSession() to add my own session variables.

    My scripts work OK outside of the manager. (i.e. regular php pages)

    The manager seems to loose the array I store in my session.
    Does anyone have any ideas what may be going on ?

    I have tried so many different things but need to get this sorted out now.

    kind regards and thanks
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      How are you adding the SESSION variables? You should simply be able to use $_SESSION[’your-field’] = ’your-value’. But I would need more clarification on exactly what you’re doing.
        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
        • 19646
        • 31 Posts
        The issue was...

        my session variable was an object.

        For some reason the manager did not like a session variable that was a class object.... huh


        Solution:

        1) output class object as an array and store that as a session variable.
        2) on new page detect the class object was empty then check if the session variable was also empty.

        - both empty then start new class object
        - class object empty but session array contains data = feed session array into class to populate it.

        Terminology may not be very correct but it worked. wink


        Thanks to sottwell for her input.

        regards



          • 28042 ☆ A M B ☆
          • 24,524 Posts
          MODx has nothing to do with that; it’s a PHP thing. It can be done, but takes some special care. Also certain object elements can’t be serialized (which is how PHP stores an object in the SESSION).

          http://www.phpriot.com/articles/intro-php-sessions/8
          http://www.php.net/manual/en/language.oop5.serialization.php
          http://stackoverflow.com/questions/132194/php-storing-objects-inside-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