Sunday 24 January 2016

Zend Framework Remember me login Form

Zend Framework Remember me login Form

Question: What is Remember Me meaning in Login Form?
When user close the browser, he logout automatically from the website due to session terminate.
When he come back on website, he need to re-login.

If we use remember me functionality, then user does not logout when he exit from website.

Question: How to use remember me in Zend Framework?
Before writing the data into session, Add following code.
Zend_Session::rememberMe(10*86400);  //Remember me for 10 days

Question: Can we use remember me with Zend_Auth?
Yes, See Example:
$result = $auth->authenticate($adapter);    
if ($result->isValid()) {
 $loginDetail = $adapter->getResultRowObject();
 $user = $adapter->getResultRowObject();   
 Zend_Session::rememberMe(7*86400); //7 days
 $namespace = new Zend_Session_Namespace('Zend_Auth'); 

Question: How to keep user login even after 2 hour of inactivity?
You need to set the expiration time,
$namespace = new Zend_Session_Namespace('Zend_Auth');
$namespace->setExpirationSeconds(7*86400); // Session will expire after 7 days  

Question: What is forgetMe?
This function complements rememberMe() by writing a session cookie that has a lifetime.

Question: What is expireSessionCookie? Why It is used?
This is method of Zend_Session used for delete the session cookie in client side.