forked from bbdoc/PoracleWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.php
97 lines (74 loc) · 2.41 KB
/
session.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
85
86
87
88
89
90
91
92
93
94
95
96
<?php
include "./config.php";
include "./include/functions.php";
if(session_status() == PHP_SESSION_NONE){
session_start();
}
set_locale();
$dbnames = explode(",", $dbname);
foreach ($dbnames as &$db) {
$conn = new mysqli($dbhost.":".$dbport, $dbuser, $dbpass, $db);
// Check connection
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: " . $conn->connect_error;
exit();
}
$sql = "SELECT * from humans WHERE id = '".$_SESSION['id']."'";
$result = $conn->query($sql) or die(mysqli_error($conn));
if ( $result->num_rows > 0 ) {
$_SESSION['dbname'] = $db;
}
}
// Set Admin Variables
if (isset($admin_id)) {
$admins = explode(",", $admin_id);
foreach ($admins as &$admin) {
if ($_SESSION['id'] == $admin)
{
$_SESSION['admin_id'] = $_SESSION['id'];
$_SESSION['admin_username'] = $_SESSION['username'];
$_SESSION['admin_dbname'] = $_SESSION['dbname'];
$_SESSION['admin_type'] = $_SESSION['type'];
}
}
}
// Get Config Items from API and Store in Session Variables
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"X-Poracle-Secret: $api_secret\r\n"
)
);
$context = stream_context_create($opts);
// Check that API is Running fine
if (!$api = file_get_contents("$api_address/api/config/poracleWeb", false, $context))
{
session_destroy();
header("Location: $redirect_url?return=error_no_api");
exit();
}
$config = file_get_contents("$api_address/api/config/poracleWeb", false, $context);
$json = json_decode($config, true);
if ( $json['status']="ok" ) {
$_SESSION['server_locale'] = $json['locale'];
$_SESSION['providerURL'] = $json['providerURL'];
$_SESSION['staticKey'] = $json['staticKey'][0];
$_SESSION['pvpFilterMaxRank'] = $json['pvpFilterMaxRank'];
$_SESSION['pvpFilterGreatMinCP'] = $json['pvpFilterGreatMinCP'];
$_SESSION['pvpFilterUltraMinCP'] = $json['pvpFilterUltraMinCP'];
$_SESSION['defaultTemplateName'] = $json['defaultTemplateName'];
} else {
session_destroy();
header("Location: $redirect_url?return=error_api_nok");
exit();
}
$areas = file_get_contents("$api_address/api/humans/".$_SESSION['id'], false, $context);
$json = json_decode($areas, true);
if ( $json['status']="ok" ) {
$_SESSION['areas'] = $json['areas'];
} else {
session_destroy();
header("Location: $redirect_url?return=error_api_nok");
exit();
}