-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.php
More file actions
57 lines (47 loc) · 1.34 KB
/
helpers.php
File metadata and controls
57 lines (47 loc) · 1.34 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
<?php
# TODO: Wrap this in an object
function get_mysqli(){
global $mysqli;
if($mysqli){
return $mysqli;
} else {
try {
$mysqli = new mysqli(mysql_host, mysql_user, mysql_pass, mysql_db);
} catch (Exception $e){
$mysqli = false;
}
if(mysqli_connect_errno()){
return false;
}
return $mysqli;
}
}
function get_mysqli_or_die(){
$mysqli = get_mysqli();
if($mysqli){ return $mysqli; }
else { die('unable to connect to database'); }
}
function filter_email($text, $html = true){
$filtered = filter_var($text, FILTER_SANITIZE_EMAIL);
return ($html ? htmlspecialchars($filtered, ENT_QUOTES | ENT_HTML5) : $filtered);
}
# htmlentities works in value attribute, so no need to use this?
#function filter_text_basic($text, $html = true){
# return ($html ? htmlspecialchars($text, ENT_QUOTES | ENT_HTML5) : $text);
#}
function filter_text($text){
return htmlentities($text, ENT_QUOTES | ENT_HTML5, 'UTF-8');
}
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
function random_b64($length = 21){
return base64url_encode(openssl_random_pseudo_bytes($length));
}
function raise($dump){
var_dump($dump);
die();
}