-
Notifications
You must be signed in to change notification settings - Fork 0
/
Authentication.php
51 lines (49 loc) · 1.33 KB
/
Authentication.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
48
49
50
51
<?php
session_start();
if(!isset($_SESSION['us1'])) // If session is not set then redirect to Login Page
{
header("Location:index.php");
}
else {
$now = time();
if ($now > $_SESSION['expire']) {
session_destroy();
}
}
?>
<?php
$con = mysqli_connect("localhost","root","","cc");
$eid= mysqli_real_escape_string($con, $_POST['mail']);
$pass= mysqli_real_escape_string($con, $_POST['password']);
if(!$con)
{
die("Connection Failed".mysqli_connect_error());
}
$result1 = mysqli_query($con,"select * from user where email = '$eid' and password = '$pass'");
$result2 = mysqli_query($con,"select * from admin where email = '$eid' and password = '$pass'");
if(mysqli_num_rows($result1)>0)
{
session_start();
$_SESSION['us1'] =$_POST['mail'];
$row = mysqli_fetch_assoc($result1);
$_SESSION['us2']=$row['Name'];
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (600);
header('Location: user.php');
}
elseif(mysqli_num_rows($result2)>0)
{
session_start();
$_SESSION['us1'] =$_POST['mail'];
$row = mysqli_fetch_assoc($result2);
$_SESSION['us2']=$row['Name'];
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (600);
header('Location: admin.php');
}
else
{
echo "<script>alert('LoginFailed');</script>";
header("Location:index.php");
}
?>