blob: 2ac7101d83669f30cdaa418ba0119ece0abe8915 (
plain)
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
|
<?php
include 'database.php';
function login(){
$email = $_POST['email'];
$password = $_POST['password'];
$query = "SELECT * FROM user where EMAIL='".$email."';";
$result = mysql_query($query);
$user = array();
if(mysql_num_rows($result) > 0) {
$query = "SELECT * FROM user where email='".$email."' and password='".$password."';";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_assoc($result)) {
$user = $row;
$user["result"] = 0;
$_SESSION['user_id'] = $user['user_id'];
$_SESSION['user_name'] = $user['name'];
$_SESSION['user_email'] = $user['email'];
}
} else {
$user["result"] = 1; //wrong password
}
} else {
$user["result"] = 2; //user not registered
}
echo json_encode($user);
}
$action = $_POST['action'];
connectDB();
session_start();
if ($action == "login") {
login();
} else if ($action == "logout") {
unset($_SESSION['user_id']);
unset($_SESSION['user_name']);
unset($_SESSION['user_email']);
session_destroy();
} else {
echo "Invalid POST action.";
}
closeDB();
?>
|