-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
148 lines (119 loc) · 4.51 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
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
<?php
ob_start();
session_start();
include("backend/connect.php");
$emailErr = $passErr = $loginErr = "";
$email = $password = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = htmlspecialchars($_POST["email"]);
}
if (empty($_POST["password"])) {
$passErr = "Password is required";
} else {
$password = $_POST["password"];
}
if (empty($emailErr) && empty($passErr)) {
$query = "SELECT id, username, email, pass, role, pp FROM users WHERE email=?";
$stmt = $conn->prepare($query);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($id, $username, $email, $hashed_password, $role, $pp);
if ($stmt->fetch()) {
if (password_verify($password, $hashed_password)) {
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
$_SESSION["email"] = $email;
$_SESSION["role"] = $role;
if (isset($_COOKIE['cart'])) {
$existing_cart = isset($_COOKIE['cart']) ? unserialize($_COOKIE['cart']) : array();
foreach ($existing_cart as $product_id) {
echo $product_id;
include("backend/connect.php");
$getProductQuery = "SELECT * FROM product WHERE id = '$product_id'";
$getProductResult = mysqli_query($conn, $getProductQuery);
if ($getProductResult) {
if ($productRow = mysqli_fetch_assoc($getProductResult)) {
$price = $productRow['price'];
$newprice = $price;
$userquery = "SELECT *FROM cart ";
$insertQuery = "INSERT INTO cart (user_id, product_id, quantity, total_amount) VALUES ('$id', '$product_id', '1', '$newprice')";
$insertResult = mysqli_query($conn, $insertQuery);
}
}
}
setcookie('cart', '', time() - 3600);
header("Location: profile.php");
exit();
} else {
header("Location: profile.php");
exit();
}
if (isset($_POST["remember"])) {
setcookie("id", $id, time() + (60 * 60 * 24), '/');
}
header("Location: profile.php");
exit();
} else {
$loginErr = "Invalid password";
}
} else {
$loginErr = "Email not found";
}
}
}
$conn->close();
ob_end_flush();
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../style/login.css">
</head>
<body>
<div id="loading">
<h1>loading</h1>
</div>
<section>
<div class="imgbox">
<img src="/img/loginimg.jpg">
</div>
<div class="content">
<a class="mainpage" href="profile.php">Ana Sayfa</a>
<div>
<h3>Login</h3>
</div>
<form action="login.php" method="POST" id="myform">
<label for="">E-mail</label>
<input type="email" name="email" placeholder="E-mail">
<p class="erortext">
<?php echo $emailErr ?>
</p>
<label for="">Password</label>
<input type="password" name="password" placeholder="Password">
<p class="erortext">
<?php echo $passErr ?>
</p>
<div class="chb">
<span style="display: flex;"><input type="checkbox" name="remember"><label for="">Remember
me</label></span>
<a href="singup.php" style="position: relative; right:30px;">Singup</a>
</div>
<div class="btn">
<input type="submit" name="login" value="Sing up">
</div>
<p class="erortext center">
<?php echo $loginErr
?>
</p>
</form>
</div>
</section>
<script src="jsc/app.js"></script>
</body>
</html>