-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
69 lines (59 loc) · 1.72 KB
/
init.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
<?php
use Package\Middleware\Token;
use Package\App\Session;
use Package\App\Input;
use Ramsey\Uuid\Uuid;
define('ROOT', "{$_SERVER['DOCUMENT_ROOT']}/Peirtual/");
date_default_timezone_set("Asia/Jakarta");
function view($view, $device = 'desktop', $data = []){
if ($device === 'desktop') $file = __DIR__."/views/desktop/{$view}.php";
elseif ($device === 'mobile') $file = __DIR__."/views/mobile/{$view}.php";
else $file = false;
if (file_exists($file)) {
if (!empty($data)) extract($data);
include_once $file;
}
else die('Request Not Found');
}
function csrftoken($reset = false){
if ($reset) {
Session::set('csrftoken', Token::generate());
}else if (!Session::get('csrftoken')) {
Session::set('csrftoken', Token::generate());
};
return Session::get('csrftoken');
}
function uuid(){
$id = Uuid::uuid4()->toString();
return substr($id, 0, strpos($id, "-"));
}
function csrfverify(){
return Token::verify(csrftoken(), (Input::get('csrftoken')) ? Input::get('csrftoken') : '');
}
function baseurl(){
return sprintf(
"%s://%s%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
$_SERVER['SERVER_NAME'],
':'.$_SERVER['SERVER_PORT'].'/Peirtual'
);
}
function requesturl(){
return sprintf(
"%s://%s%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
$_SERVER['SERVER_NAME'],
':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']
);
}
function redirect($url){
if (!headers_sent()){
header('Location: '.$url);
exit();
}else {
die(
'<script type="text/javascript">window.location.href="'.$url.'";</script>
<noscript><meta http-equiv="refresh" content="0;url='.$url.'" /></noscript>'
);
}
}