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

    I am sure the answer is simple, or maybe not. In this post, some 2 years ago ..the guy was left as he came .
    This is the first time I got dealing with sessions in Revo. I have killed this entire day on the subject, searching and trying.

    All I want is to set this
     $_SESSION['username'] = $Name;
    to run before any code in the page. I need the page to run within MODx and not without.
    I know Revo starts the session and does its own thing, but surely there is a way (that makes sense) to add custom sessions.

    This is the only thing stopping me from fully integrating this rather beautiful user chat script
    I tried a MODx plugin, but I guess I was not certain how, or what system event to hinge it on.

    I'd be most grateful for any positive leads.
    Cheers.
      TinymceWrapper: Complete back/frontend content solution.
      Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
      5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: donshakespeare at Jun 24, 2013, 05:58 PM
      Hello everybody,

      I am sure the answer is simple, or maybe not. In this post, some 2 years ago ..the guy was left as he came .
      This is the first time I got dealing with sessions in Revo. I have killed this entire day on the subject, searching and trying.

      All I want is to set this
       $_SESSION['username'] = $Name;
      to run before any code in the page. I need the page to run within MODx and not without.
      I know Revo starts the session and does its own thing, but surely there is a way (that makes sense) to add custom sessions.

      This is the only thing stopping me from fully integrating this rather beautiful user chat script
      I tried a MODx plugin, but I guess I was not certain how, or what system event to hinge it on.

      I'd be most grateful for any positive leads.
      Cheers.

      That should work in a Snippet just fine. Maybe you should describe what problem you are having with this...
        • 3749
        • 24,544 Posts
        The only thing I can think of that would cause trouble is if the user is in a different domain (maybe due to switching contexts) when the $_SESSION variable is read than the one where it was set.

          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
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Changing the username like that could be a problem. I would be inclined to use a different key for storing that, such as $_SESSION['chatuser']. It's always safer to stay away from the key words that MODx uses internally.

          You can take care of the subdomain SESSION issue by setting session_cookie_domain in your System Settings (notice the leading "."). http://rtfm.modx.com/display/revolution20/session_cookie_domain [ed. note: sottwell last edited this post 13 years, 3 months ago.]
            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
            • 42562
            • 1,145 Posts
            Thanks for the feedback.
            I have used these few days to test my work, and to make sure I am not the one going crazy; alas I am not convinced of the present state of my mind.

            Still the same problem: the value does not register; the session, chatusername, remains empty.
            Or should I say, the value is not transferred to the chat script looking for it on that page.
            Meanwhile, this works perfectly outside MODx: the chatusername is logged and used throughout the whole chatting activity.

            @opengeek . I used a snippet.
            So, I created a page,
            with an empty template
            with a call to a snippet that has this content $_SESSION['chatusername'] = "TestUserName";
            dumped in complete <html> code

            @BobRay . For now, this is within the same domain, and the same context.

            @sottwell . I found it, as you suggested, more convenient to use a different variable, so I change it.

            Anyone know where MODx starts its session? If as last and desperate resort, I should love to alter it for my needs.
            I am not the one to give up on something that is possible, and would deeply appreciate any assistance.
              TinymceWrapper: Complete back/frontend content solution.
              Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
              5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
              • 32699 ☆ A M B ☆
              • 427 Posts
              I inject content into the $_session all of the time. It is as simple as:

              Snippet call -- note the uncached call <=- probably your issue the first value can get cached into the page and subsequent users will get the same value as the first person if this is cached....
              [[!setChatUser?chatName=`[[!+modx.user.username]]`]]


              Snippet
              // YOU MIGHT WANT TO PUT SOME BLOCKS IN HERE
              //// MAKE SURE USERS HAVE AN ID > 0 IF NOT MAKE THEM LOG IN.
              //// TEST TO SEE IF THE CURRENT USER ALREADY HAS A $_SESSION['chatusername'] THEN SKIP IT
              $_SESSION['chatusername'] = $scriptProperties['chatName'];
              return;
              


              Check it:
              print_r($_SESSION);
              
                Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

                Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
                • 42562
                • 1,145 Posts
                Hello Shawn,

                Thanks for the feedback
                I already called the script uncached when I integrated the chat with my users; taking care of logged and unlogged users.
                Everything works perfectly in my chat file which loads MODx externally.

                Since it did not work in MODx proper, I reduced it to what I have above, for diagnostic purposes
                $_SESSION['chatusername'] = "TestUserName";

                The session id is set but the value is not transferred to the chat script looking for it on that page.
                The print_r($_SESSION); or print_r($_SESSION['chatusername']); command, which proves the presence of the value, strangely enough, only works in the snippet where my session was set.

                I tried print_r($_SESSION['chatusername']); in a second snippet within the same resource...but no output.
                What could be the problem. Why isn't it going global?

                Thanks.

                MODx 2.2.7
                  TinymceWrapper: Complete back/frontend content solution.
                  Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                  5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                  • 42562
                  • 1,145 Posts
                  The ANSWERED flag kept showing by itself today...just in case, this is not yet answered
                    TinymceWrapper: Complete back/frontend content solution.
                    Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                    5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.