-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign_in.php
80 lines (61 loc) · 2.19 KB
/
sign_in.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
<?php
// Start a new or resume the existing session
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$database_name = "responsive_web";
// Create connection
$DbConn = new mysqli($servername, $username, $password, $database_name);
// Check connection
if ($DbConn->connect_error) {
die("Connection failed: " . $DbConn->connect_error);
}
// Signin form submission
if (isset($_POST['submit']) && isset($_POST['identifier']) && isset($_POST['password'])) {
$identifier = $_POST['identifier']; // Can be either email or username
$password = $_POST['password'];
// Check if user exists in the signup table
$sql_query = "SELECT * FROM signup WHERE (email = '$identifier' OR username = '$identifier') AND password = '$password'";
$result = $DbConn->query($sql_query);
if ($result && $result->num_rows > 0) {
$row = $result->fetch_assoc();
$username = $row['username'];
// Store the username in the session
$_SESSION['username'] = $username;
// Redirect to index.html
header("Location: index.php");
exit();
} else {
// User not found or incorrect password, redirect to signIn.html
echo "Invalid username or password";
header("Refresh: 3; URL=sign_in.php");
exit();
}
}
$DbConn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sign In</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<main class="signinbody">
<form action="sign_in.php" method="POST" class="form" id="signinForm">
<div class="backgroundin"></div>
<a href="sign_in.php"><h1 class="form-title" id="signin">Sign In</h1></a>
<label for="identifier">Email or Username:</label>
<input type="text" id="identifier" name="identifier" placeholder="Email or Username" required />
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Password" required />
<button type="submit" name="submit">Sign In</button>
<p>Don't have an account? <a href="sign_up.php">Sign Up</a></p>
</form>
</main>
<script src="script.js"></script>
</body>
</html>