-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
60 lines (47 loc) · 1.39 KB
/
action.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
<?php
print_r($_POST);
session_start();
require_once('config/_db.php');
switch($_POST['type']):
case 'register':
$statement = "INSERT INTO users (name, email, password, facname) VALUES(:name, :email, :password, :facname)";
$insert = $conn->prepare($statement);
$insert->bindValue(':name', $_POST['name']);
$insert->bindValue(':email', $_POST['email']);
$insert->bindValue(':password', $_POST['password']);
$insert->bindValue(':facname', $_POST['facname']);
$insert->execute();
break;
case 'login':
$statement = "SELECT * FROM users WHERE email = '".$_POST['email']."';";
$query = $conn->query($statement);
$query->setFetchMode(PDO::FETCH_ASSOC);
$row = $query->fetch();
if(empty($row))
{
$_SESSION['err'] = 'User does not exist';
go();
}
if($row['password'] == $_POST['password'])
{
$_SESSION['email'] = $_POST['email'];
$_SESSION['user'] = $row['name'];
} else
{
$_SESSION['err'] = 'Wrong Password';
}
go();
break;
case 'logout':
session_destroy();
unset($_SESSION);
break;
default:
die('Invalid Action. Please report this incident.');
endswitch;
go();
function go()
{
header('Location: index.php');
}
?>