Zend Framework Session: Automatic Expiration


Zend Framework Session Step By Step Tutorial - Part 6: We can set limited time for a namespace. For this feature, we called namespace expiration. Example, we want to count number of page request by a person in one minute. After 1 minute, he will be counted as new person. So, the code like this:

We try at loginform. Open UserController.php within application/controllers. Update loginFormAction():

  public function loginFormAction()
  {
	
    $ns = new Zend_Session_Namespace('HelloWorld');

	if(!isset($ns->yourLoginRequest)){
	    $ns->yourLoginRequest = 1;
	}else{
	    $ns->yourLoginRequest++;
	}
	
	$ns->setExpirationSeconds(60);
	 
    $request = $this->getRequest();      
	$this->view->assign('request', $ns->yourLoginRequest);
	$this->view->assign('action', $request->getBaseURL()."/user/auth");  
    $this->view->assign('title', 'Login Form');
    $this->view->assign('username', 'User Name');	
    $this->view->assign('password', 'Password');	
	
  }

You can set only at a particular key (e.g, yourLoginRequest):

$ns->setExpirationSeconds(60,'yourLoginRequest');


Series this article:
Zend Framework Session: Introduction
Zend Framework Session: Using Namespace
Zend Framework Session: Accessing Session Data
Zend Framework Session: Seing All Values at Namespace
Zend Framework Session: Locking and Unlocking Namespace
Zend Framework Session: Automatic Expiration

Bookmark and Share Tag: framework, zend, zend framework, session, namespace Category: PHP Framework Post : April 24th 2008 Read: 35,280

advertisements


blog comments powered by Disqus