/
login.php
executable file
·101 lines (82 loc) · 1.92 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
session_start();
//include the DB connections details here
include("db.php");
class User
{
var $userLogin;
var $userPassword;
var $fullName;
var $userType;
var $userImage;
function User()
{
}
function setUserLogin($value)
{
$this->userLogin=$value;
}
function getUserLogin()
{
return $this->userLogin;
}
function setUserPassword($value)
{
$this->userPassword=$value;
}
function getUserPassword()
{
return $this->userPassword;
}
function setFullName($value)
{
$this->fullName=$value;
}
function getFullName()
{
return $this->fullName;
}
function setUserType($value)
{
$this->userType=$value;
}
function getUserType()
{
return $this->userType;
}
function setUserImage($value)
{
$this->userImage=$value;
}
function getUserImage()
{
return $this->userImage;
}
}
//check if the user exist in DB
$sql = "SELECT * FROM user WHERE login = '$_POST[login]'" .
" AND password = '$_POST[password]'";
$user_data = mysql_query($sql, $con);
$row = mysql_fetch_array($user_data);
if (empty($row['login']))
{
//redirect to registration page
$to = 'not-exist.html';
header('Location: '. $to);
exit;
}
//put user data in Model (User Object)
$user01 = new User();
$user01->setUserLogin($row['login']);
$user01->setUserPassword($row['password']);
$user01->setFullName($row['fullname']);
$user01->setUserType($row['usertype']);
$user01->setUserImage($row['image']);
//put user data in session
$_SESSION['user'] = $user01;
//redirect to the HOME page
$to = 'home.php';
header('Location: '. $to);
mysql_close($con);
exit;
?>