-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartSession.php
More file actions
32 lines (24 loc) · 805 Bytes
/
Copy pathStartSession.php
File metadata and controls
32 lines (24 loc) · 805 Bytes
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
<?php
session_start();
require_once ('Adaptation.php');
// If user has already been authenticated
function authenticatedUser()
{
global $DBPasswords;
return isset($_SESSION['Email']) && !empty($_SESSION['Email']) &&
isset($_SESSION['UserRole']) && !empty($_SESSION['UserRole']) &&
isset($DBPasswords[$_SESSION['UserRole']]);
}
if (authenticatedUser())
$DBName = $_SESSION['UserRole'];
else
$DBName = NO_ROLE;
$DBPassword = $DBPasswords[$DBName];
// remove before submission
// printf("Connecting to DB as '%s'/'%s'<br/>", $DBName, $DBPassword);
$db = new mysqli(DATA_BASE_HOST, $DBName, $DBPassword, DATA_BASE_NAME);
if ($db->connect_errno != 0) // if connection not successful
{
echo "Error: failed to make a MySQL connection: " . $db->connect_error . "<br/>";
return -1;
}