-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelper.php.save.1
More file actions
executable file
·166 lines (126 loc) · 4.22 KB
/
helper.php.save.1
File metadata and controls
executable file
·166 lines (126 loc) · 4.22 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
// Retrieved from https://stackoverflow.com/questions/6768793/get-the-full-url-in-php
function url_origin( $s, $use_forwarded_host = false ) {
$ssl = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on' );
$sp = strtolower( $s['SERVER_PROTOCOL'] );
$protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
$port = $s['SERVER_PORT'];
$port = ( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '' : ':'.$port;
$host = ( $use_forwarded_host && isset( $s['HTTP_X_FORWARDED_HOST'] ) ) ? $s['HTTP_X_FORWARDED_HOST'] : ( isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : null );
$host = isset( $host ) ? $host : $s['SERVER_NAME'] . $port;
return $protocol . '://' . $host;
}
function full_url( $s, $use_forwarded_host = false ) {
return url_origin( $s, $use_forwarded_host ) . $s['REQUEST_URI'];
}
function json_encode_noescape($a=false)
{
if (is_null($a)) return 'null';
if ($a === false) return 'false';
if ($a === true) return 'true';
if (is_scalar($a))
{
if (is_float($a))
{
// Always use "." for floats.
return floatval(str_replace(",", ".", strval($a)));
}
if (is_string($a))
{
static $jsonReplaces = array(array("\\", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
}
else {
return $a;
}
}
$isList = true;
for ($i = 0, reset($a); $i < count($a); $i++, next($a))
{
if (key($a) !== $i)
{
$isList = false;
break;
}
}
$result = array();
if ($isList)
{
foreach ($a as $v) $result[] = json_encode_noescape($v);
return '[' . join(',', $result) . ']';
}
else
{
foreach ($a as $k => $v) $result[] = (is_string($k) ? json_encode_noescape($k) : '"'.json_encode_noescape($k). '"') .':'.json_encode_noescape($v);
return '{' . join(',', $result) . '}';
}
}
function secure(){
$timelimit=1200;
$tempTime=time();
//include("templates/check-event-exists.php");
include("connection.php");
$get_event_stmt = $db->prepare("SELECT admin FROM event WHERE ID =:id");
$tempid= $_GET["id"];
$get_event_stmt->bindValue(":id", $tempid);
$get_event_stmt->execute();
$get_event_res = $get_event_stmt->fetchAll(PDO::FETCH_ASSOC);
if(count($get_event_res) != 1) {
die();
}
if($tempTime- $_SESSION['timestamp']>$timelimit){
header("Location: http://10.5.11.121/emmett/eventApp-data/templates/logout.php/");
die("session time expired");
}
$get_event_res = $get_event_res[0];
if(!is_null($get_event_res['admin']) && (!isset($_SESSION["username"])||$get_event_res['admin']!=$_SESSION['username'])){
header("Location: http://10.5.11.121/emmett/eventApp-data/templates/logout.php");
die();
}
$_SESSION['timestamp']=$tempTime;
}
function eventSecure(){
$timelimit=1200;
$tempTime=time();
include("connection.php");
if(!isset($_SESSION['username'])){
header("location: http://10.5.11.121/emmett/eventApp-data/templates/logout.php");
die();
}
if($tempTime- $_SESSION['timestamp']>$timelimit){
header("Location: http://10.5.11.121/emmett/eventApp-data/templates/logout.php");
die('session time expired');
}
$_SESSION['timestamp']=$tempTime;
}
function getEventId() {
global $db;
if (!($get_event_stmt = $db->prepare("SELECT internal_ID FROM event where ID=:id"))) {
die("error in get event stmt");
}
if(!$get_event_stmt->bindParam(":id",$_REQUEST['id'])) {
die("error in bind param");
}
if(!$get_event_stmt->execute()) {
die("error in execute");
}
$get_event_res = $get_event_stmt->fetchAll(PDO::FETCH_ASSOC);
if(count($get_event_res) != 1) {
echo(count($get_event_res));
die("error count != 1");
}
$get_event_res = $get_event_res[0];
return $get_event_res["internal_ID"];
}
// Preserves and returns the full url with the file name at the end removed
function stripFileName() {
$url = url_origin($_SERVER);
$url .= dirname($_SERVER['REQUEST_URI']) . "/";
return $url;
}
function getParentDir() {
$url = url_origin($_SERVER);
$url .= dirname(dirname($_SERVER['REQUEST_URI'])) . "/";
return $url;
}
?>