-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
83 lines (73 loc) · 2.88 KB
/
index.php
File metadata and controls
83 lines (73 loc) · 2.88 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
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$username = $_POST["username"];
$password = MD5($_POST["password"]);
include('./Pages/db_connection.php');
$qry = 'SELECT id, username, email, fullname, profile_pic, password FROM users';
$result = mysqli_query($db_connection, $qry);
if ($result)
{
session_start();
while ($row = mysqli_fetch_assoc($result))
{
// user can login with username or email
if (($row['username'] == $username || $row['email'] == $username) && $row['password'] == $password)
{
$_SESSION['username'] = $row['username'];
$_SESSION['email'] = $row['email'];
$_SESSION['id'] = $row['id'];
$_SESSION['fullname'] = $row['fullname'];
$_SESSION['profile_pic'] = $row['profile_pic'];
header('location:./Pages/home.php');
}
}
// if user not found
$_SESSION['login_error'] = 'Invalid username or password';
}
else
{
echo 'Error: '.mysqli_error($db_connection);
}
}
?>
<!-- login page for instagram website -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log in - Instagram</title>
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<main>
<div class="login-section">
<img src="src/images/instagram-logo.png" alt="">
<div class="login-form">
<form action="index.php" method="post" enctype="multipart/form-data">
<input class="user-input" type="text" name="username"
placeholder="Phone number, username or email address">
<input class="user-input" type="password" name="password" placeholder="Password">
<input class="login-btn" type="submit" value="Log in">
<div style="color: red;">
<?php
if (isset($_SESSION['login_error']))
{
echo $_SESSION['login_error'];
unset($_SESSION['login_error']);
}
?>
</div>
<p>OR</p>
<a class="forget-pass" href="./Pages/forgot_password.php">Forgot password?</a>
</form>
</div>
</div>
<!-- signup page link -->
<div class="signupSection">
<p>Don't have an account? <a href="./Pages/signup.php">Sign up</a></p>
</div>
</main>
</body>
</html>