-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.php
More file actions
69 lines (61 loc) · 2.06 KB
/
index.php
File metadata and controls
69 lines (61 loc) · 2.06 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrapValidator.css"/>
<link href="assets/bootstrap/css/index.css" rel="stylesheet">
<title>Stuffshare - Log in</title>
<script type="text/javascript" src="assets/jquery/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="assets/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/bootstrap/js/bootstrapValidator.js"></script>
</head>
<?php
if(isset($_SESSION)){
session_destroy();
}
session_start();
$dbconn = pg_connect("host=localhost port=5432 dbname=postgres user=postgres password=postgres")
or die('Could not connect: ' . pg_last_error());
?>
<body>
<div class="container">
<div class="jumbotron">
<h2>Log In Page</h2>
<form method="post">
<input type="email" placeholder="Email" name = "user_name" id="emailplease"> <br>
<input type="password" placeholder="Password" id="un" name = "pass"><br><br>
<div>
<input class="btn btn-info" type="submit" value = "Sign In" name = "formSubmit">
<a class = "btn btn-info" role="button" href= "regpage.php">Register</a>
</div>
</form>
</div>
</div>
<?php
if (isset($_POST['formSubmit'])){
$name = $_REQUEST['user_name'];
$password=$_REQUEST['pass'];
$query = "SELECT a.admin::int FROM account a WHERE email = '$name' AND password = '$password'";
$result = pg_query($dbconn, $query) or die('Query failed: ' . pg_last_error());
$unique = pg_num_rows($result);
if($unique == 1){
$_SESSION['emailaddress'] = $name;
$adminaccess = pg_fetch_array($result,null,PGSQL_NUM)[0];
if($adminaccess){
header('Location: /adminpage.php');
}
else{
header('Location: /homepage.php');
}
exit;
}
else{
echo "\nEmail or Password is incorrect.";
}
}
?>
</body>
</html>