-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
75 lines (59 loc) · 2.06 KB
/
login.php
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
<?php
include 'config.php';
session_start();
if (isset($_POST['submit'])){
$email = mysqli_real_escape_string($conn, $_POST['email']);
$pass = mysqli_real_escape_string($conn, md5($_POST['password']));
$select_users = mysqli_query($conn, "SELECT * FROM `users` WHERE email ='$email' AND password ='$pass'") or die('query failed');
if(mysqli_num_rows($select_users) > 0){
$row = mysqli_fetch_assoc($select_users);
if ($row['user_type'] == 'admin') {
$_SESSION['admin_name'] = $row['name'];
$_SESSION['admin_email'] = $row['email'];
$_SESSION['admin_id'] = $row['id'];
header('location:admin_page.php');
}
elseif($row['user_type'] == 'user') {
$_SESSION['user_name'] = $row['name'];
$_SESSION['user_email'] = $row['email'];
$_SESSION['user_id'] = $row['id'];
header('location:inicio.php');
}
else{
$message[] = 'Email ou senha incorreta !';
}
}
}
?>
<!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>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php
if (isset($message)) {
foreach ($message as $message) {
echo '
<div class="message">
<span onclick="this.parentElement.remove();">'.$message.'</span>
</div>
';
}
}
?>
<div class="form_container">
<form action="" method="post">
<h3>Login</h3>
<input type="email" name="email" placeholder="email" required class="box">
<input type="password" name="password" placeholder="senha" required class="box">
<input type="submit" name="submit" value="Logar" class="btn">
<p>Ainda não possui uma conta ! <a href="cadastrar.php">Cadastra-te já!</a></p>
</form>
</div>
</body>
</html>