-
Notifications
You must be signed in to change notification settings - Fork 6
/
login.php
43 lines (39 loc) · 848 Bytes
/
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
<?php
include_once("treeModel.php");
if(isset($_POST['action']) && isset($_POST['username']) && isset($_POST['password']))
{
if (strlen(session_id()) < 1) {
session_start();
}
$action=$_POST["action"];
$username= $_POST["username"];
$password = $_POST["password"];
$tree = new Tree();
switch($action)
{
case 'register':
$user = $tree->createUser($username, $password);
echo "Registered";
break;
case 'login':
$user = array();
$tree->login($username, $password, $user);
echo "Login Successful";
break;
default:
echo "Something went Wrong";
session_destroy();
break;
}
if(isset($user['id']) && isset($user['name']))
{
$_SESSION['id'] = $user['id'];
$_SESSION['name'] = $user['name'];
var_dump($_SESSION);
}
else
{
session_destroy();
}
}
?>