title: Zend Framework Automatic Logout after inactivity
body: <p>I'm working on an application that houses several sub applications and I'd like to implement an auto logout after 30 minutes of inactivity. I have an AuthController with login and logout actions mapped to custom /login and /logout routes using the Bootstrap.php as well as a front controller plugin that looks like this:</p>
  
  <pre><code>class Plugin_SessionTrack extends Zend_Controller_Plugin_Abstract {
  
      public function preDispatch(Zend_Controller_Request_Abstract $request)
      {  
  
          $employeeSession = new Zend_Session_Namespace('employeeSession');
          $employeeSession-&gt;setExpirationSeconds(10);
  
      }
  }
  </code></pre>
  
  <p>I'm new to PHP and Zend, what exactly is happening to the session after 10 seconds? I have it set low for testing. What I'd like to have happen is if the time of the last request through the front controller plugin was greater than 30 minutes ago, destroy the session and log the user out and redirect them to /login.</p>
  
  <p>I can see obviously that I'm not tracking the time of the last request but my hope was that the setExpirationSeconds would be refreshed each time the user has a request come through this preDispatch method.</p>
  
  <p>Maybe a cookie needs used? I don't need to actually initiate a logout action, it can just be handled the next time the user makes a request, if they've not done anything in the last half hour the session is destroyed and they're logged out, meaning if I walk away for 45 minutes my screen still looks the same but if I click a link or try and submit a form I had up it sends me to /login. I can worry about some type of JS countdown warning later.</p>
  
  <p>Edit: Here's my bootstrap if anyone wants to see it:</p>
  
  <pre><code>class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
  {
      /**
       * Custom routes:
       * 
       * /login
       * /logout
       */
      protected function _initRoutes()
      {
  
          $router = Zend_Controller_Front::getInstance()-&gt;getRouter();
  
          $loginRoute = new Zend_Controller_Router_Route('login', array('controller' =&gt; 'auth', 'action' =&gt; 'login'));
  
          $logoutRoute = new Zend_Controller_Router_Route('logout', array('controller' =&gt; 'auth', 'action' =&gt; 'logout'));
  
          $routesArray = array('login' =&gt; $loginRoute, 'logout' =&gt; $logoutRoute);
  
          $router-&gt;addRoutes($routesArray);
  
      }
  
      protected function _initPlugins()
      {
  
          $frontController = Zend_Controller_Front::getInstance();
          $frontController-&gt;registerPlugin(new Plugin_SessionTrack());
  
      }
  }
  </code></pre>