Skip to content

Instantly share code, notes, and snippets.

@rcaneppele
Created November 17, 2015 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rcaneppele/e5e23ebb8ae1f4d5ed4c to your computer and use it in GitHub Desktop.
Save rcaneppele/e5e23ebb8ae1f4d5ed4c 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