-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.php
85 lines (75 loc) · 1.93 KB
/
config.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
<?php
$message_code = array(
'0'=>'None',
'1'=>'This email is being used by a user',
'2'=>'User successfully registered',
'3'=>'logged',
'4'=>'Email not found',
'5'=>'Incorrect password'
);
//registration section
function user_registration($email, $username, $password) {
global $message_code;
$data_path = file_get_contents('data.json');
$data = json_decode($data_path, true);
$status = '0';
foreach ($data as $item){
if($item['email'] == $email){
$status = '1';
}
}
if(!$status == '1'){
$data[] = array(
"email" => $email,
"username" => $username,
"password" => $password
);
$data = json_encode($data);
file_put_contents('data.json', $data);
$status = '2';
}
return $status;
}
//login section
function login($email, $password)
{
global $message_code;
$data_path = file_get_contents('data.json');
$data = json_decode($data_path, true);
$status = '0';
foreach ($data as $item) {
if ($email == $item['email']) {
if ($password == $item['password']) {
if (!session_id()) {
session_start();
}
$_SESSION['email'] = $email;
header("Location:home.php");
$status = '3';
} else {
$status = '5';
}
break;
} else {
$status = '4';
}
}
return $status;
}
function user_info($email)
{
global $message_code;
$data_path = file_get_contents('data.json');
$data = json_decode($data_path, true);
$user_data = false;
foreach ($data as $item) {
if ($email == $item['email']) {
$user_data = array(
"email" => $item['email'],
"username" => $item['username']
);
}
}
return $user_data;
}
?>