forked from jashgopani/Shuttergram
-
Notifications
You must be signed in to change notification settings - Fork 7
/
login.php
72 lines (71 loc) · 2.47 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
<!DOCTYPE html>
<html lang="en">
<head>
<?php require("head.php"); ?>
<link rel="stylesheet" href="login.css">
<?php
session_start();
require("bootstrap.php");
require("conn.php");
?>
</head>
<body>
<?php
if(!empty($_SESSION['name']) && !empty($_SESSION['username']) && !empty($_SESSION['email']) && !empty($_SESSION['dp'])){
header("Location:timeline.php");
};
?>
<!-- login form -->
<div class="container align-items-center">
<?php
if(isset($_POST['loginBtn'])){
$username = $_POST['username'];
$password = $_POST['password'];
if(!$conn){
die("Connection Failed ".mysqli_connect_errno());
}else{
$query = "SELECT * from user WHERE username = '$username' && password = '$password'";
if(mysqli_query($conn,$query)){
$results = mysqli_query($conn,$query);
$array = mysqli_fetch_array($results,MYSQLI_ASSOC);
if($array == NULL){ ?>
<div class="alert alert-dismissible alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Cannot find an account with the specified credentials</strong>
</div>
<?php
}else{
session_start();
$_SESSION['name'] = $array['name'];
$_SESSION['username'] = $array['username'];
$_SESSION['email'] = $array['email'];
$_SESSION['dp'] = $array['dp'];
header("Location:timeline.php");
}
}else{
die(mysqli_error());
}
}
}
?>
<div class="row justify-content-center">
<div class="col-sm-7 col-lg-6">
<div class="card">
<div class="card-header text-center"><span class="h2">Login</span></div>
<div class="card-body text-center">
<div class="form-group text-center">
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="username" id="username" class="form-control" placeholder="Username" value=""><br>
<input type="password" name="password" id="password" class="form-control" placeholder="Password"><br>
<input type="submit" value="Login" name="loginBtn" id="loginBtn" class="btn btn-block btnbg">
</div>
</div>
<div class="card-footer text-center">
<div class="h5">Not a member yet ? <a href="register.php" class="btn btn-sm btnbg">Register Here</a></div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>