Last active
April 2, 2025 12:50
-
-
Save zerobugs-oficial/4feecc412a588e396c9cba5e581f788d to your computer and use it in GitHub Desktop.
Sistema de login simples (SEM CRIPTOGRAFIA) usando PHP
This file contains hidden or 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 | |
$usuario = 'root'; | |
$senha = ''; | |
$database = 'login'; | |
$host = 'localhost'; | |
$mysqli = new mysqli($host, $usuario, $senha, $database); | |
if($mysqli->error) { | |
die("Falha ao conectar ao banco de dados: " . $mysqli->error); | |
} |
This file contains hidden or 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 | |
include('conexao.php'); | |
if(isset($_POST['email']) || isset($_POST['senha'])) { | |
if(strlen($_POST['email']) == 0) { | |
echo "Preencha seu e-mail"; | |
} else if(strlen($_POST['senha']) == 0) { | |
echo "Preencha sua senha"; | |
} else { | |
$email = $mysqli->real_escape_string($_POST['email']); | |
$senha = $mysqli->real_escape_string($_POST['senha']); | |
$sql_code = "SELECT * FROM usuarios WHERE email = '$email' AND senha = '$senha'"; | |
$sql_query = $mysqli->query($sql_code) or die("Falha na execução do código SQL: " . $mysqli->error); | |
$quantidade = $sql_query->num_rows; | |
if($quantidade == 1) { | |
$usuario = $sql_query->fetch_assoc(); | |
if(!isset($_SESSION)) { | |
session_start(); | |
} | |
$_SESSION['id'] = $usuario['id']; | |
$_SESSION['nome'] = $usuario['nome']; | |
header("Location: painel.php"); | |
} else { | |
echo "Falha ao logar! E-mail ou senha incorretos"; | |
} | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Login</title> | |
</head> | |
<body> | |
<h1>Acesse sua conta</h1> | |
<form action="" method="POST"> | |
<p> | |
<label>E-mail</label> | |
<input type="text" name="email"> | |
</p> | |
<p> | |
<label>Senha</label> | |
<input type="password" name="senha"> | |
</p> | |
<p> | |
<button type="submit">Entrar</button> | |
</p> | |
</form> | |
</body> | |
</html> |
This file contains hidden or 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 | |
if(!isset($_SESSION)) { | |
session_start(); | |
} | |
session_destroy(); | |
header("Location: index.php"); |
This file contains hidden or 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 | |
include('protect.php'); | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Painel</title> | |
</head> | |
<body> | |
Bem vindo ao Painel, <?php echo $_SESSION['nome']; ?>. | |
<p> | |
<a href="logout.php">Sair</a> | |
</p> | |
</body> | |
</html> |
This file contains hidden or 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 | |
if(!isset($_SESSION)) { | |
session_start(); | |
} | |
if(!isset($_SESSION['id'])) { | |
die("Você não pode acessar esta página porque não está logado.<p><a href=\"index.php\">Entrar</a></p>"); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tcc agradece, meu grande amigo é nós pae