Welcome Guest, Not a member yet? Register   Sign In
redirecting and alerting after the session has cleared
#1

(This post was last modified: 01-25-2018, 10:52 AM by ciadmin. Edit Reason: cleared ransom note formatting )

I have found that if I leave my system sitting at one of its views for more than 7200 seconds (with no interaction) the session variable clears and I lose track of the name and userid of the user. What I'd like to do is popup an alert saying "you have been logged out" and display my Users view which is the login screen.

if (!isset($_SESSION['isUserLoggedIn'])){ //if the session has cleared log the user out

redirect('Users');
}

I have also tried $this->load->view('Users/logout'); instead of the redirect but "no go"

The problem is that I am unable to alert and I am also unable to send the user back to the login screen. I have researched and discovered that I need to do this in javascript since PHP doesn't become active until the user interacts with the screen. But, my HTML file, which has some js on it, is not even displaying at this time. Is there any type of event I can get when $config['sess_expiration'] fires?
proof that an old dog can learn new tricks
Reply
#2

The alert idea would require some js that polls periodically for the value of $_SESSION['isUserLoggedIn']. Kind of resource intensive though it might be possible to use a webworker to handle the polling.

I'm curious why you are unable to redirect to the login page.
Reply
#3

Hey Dave. The redirect works now. I had the URL wrong. Now I have

redirect('/Users/login/');

and it works.

I still wish I could popup a message. Well I guess I am ok for now. Now back to my OrgChart issue!

Thx
proof that an old dog can learn new tricks
Reply
#4

(This post was last modified: 01-25-2018, 12:21 PM by richb201.)

I am still fooling with the alert. I have this in a file called javascript_funcs.js

$(document).click(function(){
   if(typeof timeOutObj != "undefined") {
   clearTimeout(timeOutObj);
}

   timeOutObj = setTimeout(function(){
   localStorage.clear();
   window.location = "/";
   alert ("logoff due to inactivity");
}, 6000);   //will expire after 6 secs
});

I have it set to 6 secs just for testing. What I am finding is that unless a user clicks on item on my menu, the timer is never set. So for example a user logins in and then doesn't do anything, the click event never fires and then the logoff timer never fires.Is there some way to force the set Timer to start when the system first comes up (without a user click)?
proof that an old dog can learn new tricks
Reply
#5

I figured it out. I will use $(document).ready(function() to start up the timer.
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB