-
-
Save bergpb/1fd4f91d935dc01c39e976bc0f4fc9c0 to your computer and use it in GitHub Desktop.
Configurando Session-Timeout no PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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