-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthenticate.php
More file actions
54 lines (54 loc) · 1.29 KB
/
authenticate.php
File metadata and controls
54 lines (54 loc) · 1.29 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
<!DOCTYPE html>
<html>
<head>
<title>Verify</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
session_start();
$servername="localhost";
$username="root";
$password="root";
$dbname="phplogin";
$con = mysqli_connect($servername, $username, $password, $dbname);
if (mysqli_connect_error())
{
die ('Failed to connect ' . mysqli_connect_error());
}
if ( !isset($_POST['email'], $_POST['password']) )
{
die ('Please fill both email and password field!');
}
if ($stmt = $con->prepare('SELECT id, password FROM history WHERE email = ?'))
{
$stmt->bind_param('s', $_POST['email']);
$stmt->execute();
$stmt->store_result();
}
if ($stmt->num_rows > 0)
{
$stmt->bind_result($id, $password);
$stmt->fetch();
if ($_POST['password'] === $password)
{
session_regenerate_id();
$_SESSION['loggedin'] = TRUE;
$_SESSION['email'] = $_POST['email'];
$_SESSION['id'] = $id;
header('Location: home.php');
}
else
{
echo '<h2>Incorrect Password!</h2>';
}
}
else
{
echo '<h2>Invalid!<h2>';
}
$stmt->close();
?>
</body>
</html>