-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinitialize.php
More file actions
73 lines (55 loc) · 2.1 KB
/
Copy pathinitialize.php
File metadata and controls
73 lines (55 loc) · 2.1 KB
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
<?php
// Prevents JavaScript XSS attacks aimed to steal the session ID
ini_set('session.cookie_httponly', 1);
// Session ID cannot be passed through URLs
ini_set('session.use_only_cookies', 1);
// Use a secure HTTPS connection
ini_set('session.cookie_secure', 1);
// Same site cookie
ini_set('session.cookie_samesite', 'Lax');
// Make sure cookie works also on subdomains (e.g. www.roaddanger.org & nl.roaddanger.org)
$serverName = $_SERVER['SERVER_NAME'];
// Extract domain parts
$parts = explode('.', $serverName);
// If there are only 2 parts (like roaddanger.org), use the whole name with a leading dot
// Otherwise, remove the first part (the subdomain)
$domain = (count($parts) <= 2) ? '.' . $serverName : substr($serverName, strpos($serverName, '.'));
ini_set('session.cookie_domain', $domain);
session_start();
date_default_timezone_set('Europe/Amsterdam');
setlocale(LC_MONETARY, 'nl_NL');
mb_internal_encoding('UTF-8');
// Environment constants
define("IS_DEVELOPMENT_ENVIRONMENT", $_SERVER['SERVER_NAME'] === 'localhost' || str_ends_with($_SERVER['SERVER_NAME'], '.test'));
const IS_PRODUCTION_ENVIRONMENT = ! IS_DEVELOPMENT_ENVIRONMENT;
// Show debug info only when developing or testing, not in production:
// - localhost
// - test domains ending in *.test
if (IS_DEVELOPMENT_ENVIRONMENT) {
ini_set('display_errors', 1);
error_reporting(E_ALL);
} else {
ini_set('display_errors', 0);
error_reporting(0);
}
require_once __DIR__ . '/config.php';
require_once 'database.php';
require_once 'users.php';
require_once 'general/utils.php';
// Send all unhandled Exceptions and Errors to the main developer
//set_error_handler('globalErrorHandler');
//set_exception_handler('globalExceptionHandler');
//register_shutdown_function('globalShutdownHandler');
try {
$database = new Database();
try {
$database->open();
} catch (\Exception $e){
die('Internal error: Database connection failed');
}
$database->loadCountries();
$user = new User($database);
} catch (\Exception $e) {
$message = 'Internal error: Initialization failed: ' . $e->getMessage() . "\n\n" . $e->getTraceAsString();
die($message);
}