Problems updating page and scrolling user after idle period

Asked

Viewed 106 times

0

I need to deploy the user after an idle time. I can update and destroy the session but it’s not working as I need it. That in the case is that php does not identify as an activity performed by the user the automatic update of javascript after time.

I will insert how I update the page automatically with JS.

var refreshIntervalId = setInterval(fname, 180000);


function fname() {
  window.location.reload(true);
  // window.location.reload(); use this if you do not remove cache
}

Now I’ll show you how my function is in php, in the validation page I call the global variable:

$tempolimite = 3000;
//fim das configurações de fusu horario e limite de inatividade//

   // aqui ta o seu script de autenticação no momento em que ele for validado você seta as configurações abaixo.//
   // seta as configurações de tempo permitido para inatividade//
    $_SESSION['registro'] = time(); // armazena o momento em que autenticado //
    $_SESSION['limite'] = $tempolimite; // armazena o tempo limite sem atividade //
   // fim das configurações de tempo inativo//

Now where really I check things on my main page:

$registro = $_SESSION['registro'];
 $limite = $_SESSION['limite'];

 if($registro)// verifica se a session  registro esta ativa
 {
  $segundos = time() - $registro;
 }
 // fim da verificação da session registro

 /* verifica o tempo de inatividade 
 se ele tiver ficado mais de 300 segundos sem atividade ele destroi a session
 se não ele renova o tempo e ai é contado mais 300 segundos*/
 if($segundos>$limite)
 {
  session_destroy();
  die( "Sua seção expirou.");

 }
 else{
  $_SESSION['registro'] = time();
 }
 // fim da verificação de inatividade

Thank you from the community already, and I’m sorry if this is something very simple to do, but I’m really at the beginning and this is all very new to me! Stay with God and I’m sorry if this question is too obvious!

Att, Renan Godoy

  • Read through these configuration directives: Session.gc_maxlifetime on the page: https://www.php.net/manual/en/session.configuration.php. As I understand it, you need to expire after a X time if it has not been updated by your browser, and not consider whether access was made only by AJAX.

  • Romeu Gomes would be possible please, if it is not ask too much, an example of Usuability of this option in my porblema, I repeat again I am new in the world of programming, thank you very much!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.