js代码:
1 <script type="text/javascript"> 2 var maxTime = 1800; // seconds 3 var time = maxTime; 4 $('body').on('keydown mousemove mousedown', function(e){ 5 time = maxTime; // reset 6 }); 7 var intervalId = setInterval(function(){ 8 time--; 9 if(time <= 0) { 10 ShowInvalidLoginMessage(); 11 clearInterval(intervalId); 12 } 13 }, 1000) 14 function ShowInvalidLoginMessage(){ 15 // 清除cookie 16 // 提示用户 17 // 该干嘛干嘛 18 alert('您已超过30分钟无任何操作已自动退出!'); 19 location.href="/Admin/Login/tuichu"; 20 } 21 </script>
PHP代码:
1 //一段时间不操作自动退出 2 public function tuichu(){ 3 session(null); 4 session_destroy(); 5 $this->redirect('Admin/Login/index'); 6 }