forked from yashgoyal2802/CCC
-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.php
39 lines (34 loc) · 830 Bytes
/
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
<?php
if(isset($_POST["login"]))
{
$username = $_POST["username1"];
$password = $_POST["password1"];
}
function OpenCon()
{
$conn = pg_connect($_ENV['DATABASE_URL']);
return $conn;
}
function CloseCon($conn)
{
pg_close($conn);
// $conn -> close();
}
$conn = OpenCon();
if($conn === false){
die("ERROR: Could not connect.<br>" . $conn->connect_error);
}
$sql= "SELECT * FROM persons WHERE username='$username' AND password='$password'";
$result = pg_query($conn, $sql);
if(pg_num_rows($result)>0){
$cookie_name = "username";
$cookie_value = $username;
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
CloseCon($conn);
header('Location: home.php');
}else{
$error = "Your Login Name or Password is invalid";
echo "$error";
CloseCon($conn);
}
?>