-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
47 lines (34 loc) · 1.2 KB
/
index.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
<?php
include_once("config.php");
session_start();
$loginshow = $error=""; //define error variable
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
// Retrieve form data
$email = $_POST['email'];
$Password = $_POST['password'];
$sql="SELECT * from users where email='$email' AND password='$Password'";
$res = mysqli_query($mysqli,$sql);
// Check if entered credentials match the static values
if (mysqli_num_rows($res)===1)
{
$fetch_row=mysqli_fetch_assoc($res);
// Set cookies with student ID and hashed password
if($fetch_row['email']===$email && $fetch_row['password']===$Password)
{
setcookie('email', $email, time() + (86400 * 30), '/'); // Cookie set to expire in 30 days
setcookie('password', md5($Password), time() + (86400 * 30), '/');
$loginshow= "Login Successful!";
$_SESSION["name"]=$fetch_row['name'];
}
else
{
$error= "Invalid email or password";
}
} else
{
$error= "Invalid email or password";
}
header("Location:login.php? param1={$loginshow}& param2={$error}");
}
?>