Timeout-dialog is a JQuery plugin that displays a timeout popover after a certain period of time. The timeout dialog should be used whenever you want to display to the user that the logged in session is about to expire. It creates a light box with a countdown and options to stay signed in or sign out.
Requirements ¶
Yii 1.1.x, jQuery.ui core script
Usage ¶
In your layout view:
<?php
$this->widget('ext.timeout-dialog.ETimeoutDialog', array(
// Get timeout settings from session settings.
'timeout' => Yii::app()->getSession()->getTimeout(),
// Uncomment to test.
// Dialog should appear 20 sec after page load.
//'timeout' => 80,
'keep_alive_url' => $this->createUrl('/site/keepalive'),
'logout_redirect_url' => $this->createUrl('/site/logout'),
));
?>
In your SiteController:
/**
* Keep the session alive, called by timeout-dialog.
*/
public function actionKeepAlive()
{
echo 'OK';
Yii::app()->end();
}
Resources ¶
Credit ¶
timeout-dialog.js was developed by rigoneri.
Version History ¶
- 1.2 — 2013-02-27
- Fix for Yii 1.1.13 jQuery UI update.
- 1.1 — 2012-08-03
- Make the widget inherit from CJuiWidget class for better integration.
- Fixes and updates to CSS.
- 1.0 — 2012-07-05
- Initial release.
Cool
thanks very much for sharing!
=))
Link to session expired?
Nice extension.
Could you help me on link this with yii built in session expired?
what should I put in here ???
<?php
$this->widget('ext.timeout-dialog.ETimeoutDialog', array( 'timeout' => ???, 'keep_alive_url' => $this->createUrl('/site/keepalive'), 'logout_redirect_url' => $this->createUrl('/site/logout'), ));
?>
Cheers
$.trim(data)
I was forced to add data = $.trim(data) on:
keepAlive: function() { var self = this; this.destroyDialog(); $.get(settings.keep_alive_url, function(data) { data = $.trim(data); if (data == "OK") { if (settings.restart_on_yes) { self.setupDialogTimer(); } } else { self.signOut(false); } }); },
when using:
public function actionKeepAlive() { echo 'OK'; Yii::app()->end(); }
timeout
should timeout not contain of both:
Like:
settings.restarted
i dont know but i cant get this to work whitout adding settings.restarted and move window.clearInterval(self.countdown);
Like:
startCountdown: function() { var self = this, counter = settings.countdown; settings.restarted = true; this.countdown = window.setInterval(function() { counter -= 1; counterDisplay = counter + ' sekunder'; if(counter>60){ counterDisplay = Math.round(counter/60) + ' minuter'; } $("#timeout-countdown").html(counterDisplay); if (counter <= 0 && settings.restarted) { self.signOut(false); } }, 1000); }, keepAlive: function() { var self = this; this.destroyDialog(); $.get(settings.keep_alive_url, function(data) { data = $.trim(data); if (data == "OK") { if (settings.restart_on_yes) { settings.restarted = false; window.clearInterval(self.countdown); self.setupDialogTimer(); } } else { self.signOut(false); } }); },
otherwise it will logout even if i have klicked "Keep me logged in"
many open tabs can automatically logout the session
Thank you for great extension.
I am using this extension on all of my projects. However, being web based, I sometimes utilize browser tab for user to get information on some places. User can open different information on different tabs.
Some of my users reported that when opening the app on more than one tab (at least two tabs), they occasionally logged out and need to re-login to continue their works. It should not reached the time out since they were still working (entrying data or just clicking some buttons). While, it did not happen to user that only open the app in one tab.
Can you help me with this?
Cheers,
Daniel
Too early session timeout
Please note that PHP has a garbage collection setting in php.ini that is default to 1440 at least Linux Mint and Ubuntu (session.gc_maxlifetime=1440). That means that a session times out after 24 minutes/1440 seconds, even if you have set a longer session timeout in your Yii application.
ext.timeout-dialog.ETimeoutDialog FOR YII2
Please share updated version of timeout dialog for Yii2, because old one is not working with Yii2.
to make it work on multiple tabs
Can we change how the timer work by make it work only when the tab is in focus. If user leave the focus or open another tab, this counter will be stopped. Or add checking when the javascript timer reach 0, and the tab is not active then, just automatically keep login?
anyone can help?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.