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

    I have on a non-MODX site the following code:

    if (!isset($_SESSION["xx"])) {
    $_SESSION["xx"] = 1;
    }

    $a = $_SESSION["xx"];
    $a = $a + 1;

    $_SESSION["xx"] = $a;
    print "<h3>a = " . $a . "</h3>";


    This is standard a counter in a session variable. Very basic and
    straightforward.
    When refreshing the page, I get a number-count.

    Then I paste this piece of code in a snippet. [[phpsession]]
    The snippet is called from a document.

    What happens then is very very strange:
    1) The counter is not updated on refreshing the page
    2) The counter is updated after I edited/saved snippet.
    3) Another user (another PC, same outgoing IP address) gets the same
    number as I have

    When I add a php command var_dump($_SESSION) in the snippet,
    then I see all MODX session params. They look ok. I also see my
    added variable.

    This must be a very strange bug or something very stupid of me.
    Since I cannot be the first one using session I am very afraid it’s
    the latter. But what did I do wrong?

    Please help.

    Thank you.

    Bert Catsburg



      • 26435
      • 1,193 Posts
      is the page cached?
      If so, did you call the snippet uncached as [!phpsession!]

      -sD-
      Dr. Scotty Delicious, DFPA.
        Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
        All of the above... in no specific order.


        I send pointless little messages
        • 3177
        • 137 Posts
        Ah, my first encounter with the MODX caching mechanism.
        Very very sorry guys that I did not see this directly.

        Yes, calling the snippet with the "[! !]" instead of "[[ ]]" solved
        the problem.

        This discussion is closed to further replies. Keep calm and carry on.