-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthenticate.php
More file actions
35 lines (27 loc) · 1000 Bytes
/
Copy pathauthenticate.php
File metadata and controls
35 lines (27 loc) · 1000 Bytes
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
<?php
// session utils
include 'sessions.php';
// get POST information from login form
$email=$_POST["email"];
$password=$_POST["password"];
// open connection to the database
include 'config.php';
include 'opendb.php';
// get user data from the users table (assumes users table already exists!)
$result = mysqli_query($conn, "SELECT * FROM users WHERE email='" . mysqli_real_escape_string($email) . "'" . " AND password=" . "'" . mysqli_real_escape_string($password) . "'");
// authenticate user
$login = mysqli_num_rows($result) > 0;
if($login){
// set an active cookie for this username
setcookie("PHPSESSID", authenticated_session($email), time()+3600);
setcookie("user", $email, time()+3600);
header('Location: /index.php');
} else {
// logout
setcookie("PHPSESSID", authenticated_session($email), time()-3600);
setcookie("user", $email, time()-3600);
header('Location: /login.php?message=Login%20Failed');
}
// close connection to the database
include 'closedb.php';
?>