Created
January 5, 2016 01:09
-
-
Save jaonoctus/4649895079fa967503d3 to your computer and use it in GitHub Desktop.
Exemplo de login em PHP usando SESSION
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
<form action="login.php" method="post"> | |
login: <input type="text" name="login" placeholder="Só para fins demonstrativos. Não tem função."/><br/> | |
senha: <input type="password" name="senha" placeholder="Só para fins demonstrativos. Não tem função."/><br/> | |
<input type="submit" value="logar"/> | |
</form> | |
<br/> | |
<a href="secret_page.php">secret page</a> |
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
<?php | |
// validação do login aqui | |
# TODO | |
session_start(); | |
$_SESSION['logged'] = true; | |
header('Location: secret_page.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
<?php | |
session_start(); | |
session_destroy(); | |
header('Location: ./'); | |
?> |
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
<?php session_start(); ?> | |
<?php if ($_SESSION['logged']) : ?> | |
Você está logado. | |
<br/><br/> | |
<a href="logout.php">Desconectar</a> | |
<?php else : ?> | |
Você não possui acesso a esta página. | |
<meta http-equiv="refresh" content="2; url=logout.php"/> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment