-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
156 lines (123 loc) · 3.78 KB
/
index.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
session_start();
include("connection.php");
check_login($con);
//if user already logged in go to home.php
function check_login($con)
{
if (isset($_SESSION['user_id']))
{
$id = $_SESSION['user_id'];
$query = "select * from users where user_id = '$id' limit 1";
$result = mysqli_query($con,$query);
if ($result && mysqli_num_rows($result) > 0)
{
header("Location: home.php");
die;
}
}
}
$error ="";
$ok = 0;
if($_SERVER['REQUEST_METHOD'] == "POST")
{
//something was posted
$username = $_POST['username'];
$password = $_POST['password'];
//read from database
$query = "select * from users where username = '$username' limit 1";
$result = mysqli_query($con, $query);
if($result)
{
if($result && mysqli_num_rows($result) > 0)
{
$user_data = mysqli_fetch_assoc($result);
if($user_data['password'] == $password)
{
$_SESSION['user_id'] = $user_data['user_id'];
header("Location: home.php");
die;
}
else
{
$ok = 1;
$error = "Incorrect Username or Password.";
}
}
else
{
$ok = 1;
$error = "Incorrect Username or Password.";
}
}
}
?>
<!DOCTYPE html>
<html>
<head >
<title>Foody | Login </title>
<link rel="icon" href="images/tab_icon.png">
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fira+Sans+Condensed:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script defer type="text/javascript" src="index.js"></script>
<meta charset="utf-8">
<!-- delay body load for dark mode -->
<style>
body {
visibility: hidden;
opacity: 0;
}
</style>
</head>
<body>
<div class="dark-light" hidden>
<button id="button-switch" class="drk-lght-button" onclick="SwitchTheme()"><img id="img-switch" class="theme"></button>
</div>
<div class="wrapper">
<div class="empty-div">
</div>
<div class="login-div">
<div class="logo-div">
<img class="logo" src="images/foody_logo.png" alt="foody_logo">
</div>
<br>
<div class="div-form">
<br>
<label class="label-signin"> LOG IN </label>
<div>
<form method="post">
<br>
<div>
<?php
if ($ok == 1)
{
echo '<p class="login_error"> <img style="vertical-align:middle" src="images/info.png"> ';
echo $error;
echo '</p>';
}
?>
</div>
<br>
<div>
<input class="input-login" type="text" name="username" placeholder="Username" required>
</div>
<br>
<div>
<input class="input-login" type="password" name="password" placeholder="Password" required>
</div>
<br>
<div >
<input class="btn btn:hover" type="submit" value="Login">
</div>
<br>
<div class="signup-link">
Not a member? <a href="signup.php">Signup now</a>
</div>
<br>
</form>
</div>
</div>
</div>
</body>
</html>