-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
90 lines (69 loc) · 2.57 KB
/
Copy pathindex.php
File metadata and controls
90 lines (69 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
//Verifica se o user está logado
session_start();
if (isset($_SESSION['login_usuario'])) {
header("Location: controle.php");
}
//Conecta ao banco
$conexao = mysqli_connect("localhost","root","", "clientes");
$erros = array();
//Sistema de login
if (isset($_POST['btn-login'])) {
$login=$_POST['login'];
$senha=$_POST['senha'];
if (empty($login) || empty($senha)) {
echo "Campos Obrigatorios";
$erros[]="<li>Preencha todos os campos</li>";
}else {
$sql = "SELECT login FROM usuarios WHERE login='$login' ";
$resultados = mysqli_query($conexao, $sql);
if ( mysqli_num_rows($resultados) > 0) {
$senha = md5( $senha );
$sql = "SELECT * FROM usuarios WHERE login='$login' AND senha='$senha' ";
$resultados = mysqli_query($conexao, $sql);
if ( mysqli_num_rows($resultados) == 1) {
$dados = mysqli_fetch_array($resultados);
$_SESSION['id_usuario'] = $dados['id'];
$_SESSION['login_usuario'] = $dados['login'];
header("Location: controle.php");
}else {
$erros[]="<li>Usuario e senha não batem</li>";
}
}else {
$erros[]="<li>Usuario não existe</li>";
}
}
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charser="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Asap:ital,wght@1,700&family=Nunito:wght@700&family=Yellowtail&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="CSS/normalize.css">
<link rel="stylesheet" type="text/css" href="CSS/style.css">
<title>Login</title>
</head>
<body>
<nav>
<a href="index.php" >ClientCrud</a>
</nav>
<div id="div-login">
<h1 style="color: #000000">login</h1><br>
<?php
foreach ($erros as $erro) {
echo $erro;
}
?>
<form action="" method="post">
<label for="login">Login</label>
<br> <input type="text" name="login"><br>
<label for="pass">Senha</label>
<br> <input type="password" name="senha"><br><br>
<button type='submit' name='btn-login'>Entrar</button>
</form>
</div>
</body>
</html>