Welcome Guest, Not a member yet? Register   Sign In
Detecting a page refresh
#1

[eluser]bikuta[/eluser]
I'm trying to do this using session variables by checking how long ago was the request made to unload the window (the event that gets triggered in javascript).

So here's how I'm trying to do it:

When the user refreshes the window I make a synchronous ajax call to an exit function in my controller:

i.e.,
Code:
function exit() {
    $this->session->set_userdata('refresh', now());
}

Then when the page reloads the open function gets called:
Code:
function open()
{
        
   $lastRefresh = 1000;
   if ($this->session->userdata('refresh') != null)
      $lastRefresh = now() - $this->session->userdata('refresh');
   if ($lastRefresh < 5)
      echo "page was refreshed";
  
}

now my problem is that this doesn't seem to work, the time difference I'm getting is actually the time since the last time the page was loaded and not the last time the page was unloaded.

If this was working I should only be getting differences of < 5 secs as it doesn't take that long to load the page.

However it is giving me a time, e.g., 50 secs, which is the time of the last page load, i.e., the last time I called open().

Does anyone know why this is happening? It seems to be that the session cookie is not being updated correctly in the exit, but I have no idea why.




Theme © iAndrew 2016 - Forum software by © MyBB