We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48272
    • 24 Posts
    For security reasons I'd like to have a inactive user logged off after a period of time. I found something here: http://stackoverflow.com/questions/20516969/automatic-logout-after-15-minutes-of-inactive-in-php .
    What is the best way to do this in modx?! Should I modify the main template? How can I access the "session"-variable? Is there an "extra" which implements automatic logoff or check user activity?

    Thanks for you support.
      • 38309
      • 40 Posts
      Egraaf did you end up getting any joy out of this,

      I also am after a automatic logout for webusers when inactive.
        • 48272
        • 24 Posts
        Sorry I didn't visit this forum for a while. No, I don't have a solution yet.
          • 3749
          • 24,544 Posts
          Try putting this in a snippet and putting a tag for the snippet in the Template(s).
          I've made a couple of changes.


          if (! isset($_SESSION['timestamp'])) {
              $_SESSION['timestamp'] = time(); //set new timestamp
          }
          if(time() - $_SESSION['timestamp'] > 900) { //subtract new timestamp from the old one
              echo"<script>alert('15 Minutes over!');</script>";
              unset($_SESSION['username'], $_SESSION['password'], $_SESSION['timestamp']);
              $_SESSION['logged_in'] = false;
              $modx->sendErrorPage();
              exit;
          } else {
              $_SESSION['timestamp'] = time(); //set new timestamp
          }


          I don't think it will work because using echo with JS in a snippet usually doesn't work, but it's worth a try.
            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