This is an old version of this answer!
Return to the current answerHi!
My tip is following - step by step:
(1)
Put the expire time into app.yml :
(2)
On first visit put one session on server - for example at login.
In login action , you set the expire timestamp , "global":
(3)
You make an action, only for check the TTL expiring , later for ajax calls:
(4)
Finally in the template :
******-
Thats it, you can make this with cookies, or other tricks too, but this is the most simple - i think.
I hope, i could help you!
Best regards :
Gergely Szilagyi
My tip is following - step by step:
(1)
Put the expire time into app.yml :
all:
project:
my_expire_ttl: 3600 # this means 1 hour
(2)
On first visit put one session on server - for example at login.
In login action , you set the expire timestamp , "global":
if( ! $this->getUser()->hasAttribute('my_expire') OR $this->getUser()->getAttribute('my_expire') < time() )
{
$this->getUser()->setAttribute('my_expire', sfConfig::get('app_project_my_expire_ttl') + time() );
}
(3)
You make an action, only for check the TTL expiring , later for ajax calls:
public function executeCheckMyExpire(sfWebRequest $request )
{
$need_redirect = "";
if(
$request->isXmlHttpRequest()
AND
(
! $this->getUser()->isAuthenticated()
OR
$this->getUser()->getAttribute('my_expire') < time()
)
)
{
$need_redirect = "YOUR LINK TO REDIRECT IN AJAX RESPONSE";
}
return $this->renderText($need_redirect);
}
(4)
Finally in the template :
<script>
var only_one_in_one_time_flag = true;
function checkExpire()
{
// only run the function in one thread!
if(only_one_in_one_time_flag)
{
only_one_in_one_time_flag = false;
jQuery.get("__MODULE__/checkMyExpire", function (data) {
data = jQuery.trim(data);
if(data.length > 10)
{
// you know, redirect need, cause there is a string
window.location.href = data;
}else
{
// do nothing, cause the user is already logged in, or the expire flag is still alive.
}
// if the async call is ended, then function is callable again
only_one_in_one_time_flag = true;
});
}
}
setInterval("checkExpire()",10000); // in 10 sec in enougth to call
</script>
******-
Thats it, you can make this with cookies, or other tricks too, but this is the most simple - i think.
I hope, i could help you!
Best regards :
Gergely Szilagyi
Gergely Szilagyi | 02/21/11 at 7:14am
