Skip to content

Instantly share code, notes, and snippets.

@bergpb
Forked from rcaneppele/SessionTimeout.php
Created February 24, 2021 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bergpb/1fd4f91d935dc01c39e976bc0f4fc9c0 to your computer and use it in GitHub Desktop.
Save bergpb/1fd4f91d935dc01c39e976bc0f4fc9c0 to your computer and use it in GitHub Desktop.
Configurando Session-Timeout no PHP
session_start();
$timeout = 600; // Tempo da sessao em segundos
// Verifica se existe o parametro timeout
if(isset($_SESSION['timeout'])) {
// Calcula o tempo que ja se passou desde a cricao da sessao
$duracao = time() - (int) $_SESSION['timeout'];
// Verifica se ja expirou o tempo da sessao
if($duracao > $timeout) {
// Destroi a sessao e cria uma nova
session_destroy();
session_start();
}
}
// Atualiza o timeout.
$_SESSION['timeout'] = time();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment