-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.php
47 lines (39 loc) · 1.04 KB
/
helpers.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
<?php
$ROOT = dirname(__FILE__);
$path = $_SERVER['DOCUMENT_ROOT'];
function redirect($route) {
header("Location: ".$ROOT.'/'.$route);
die();
}
function page($name, $conn = NULL){
require_once("pages/head.html");
require_once("pages/".$name);
require_once("pages/bottom.html");
}
function error($code, $conn, $log = NULL){
$description = '';
switch($code){
case 400: $description = "Bad Request Error"; break;
case 404: $description = "Not Found"; break;
}
header("HTTP/1.0 $code $description");
$arr = array($code, $description);
$stmt = $conn->prepare("INSERT INTO error_logs (`report`, `code`, `location`) VALUES (?, ?, ?)");
if ($stmt === FALSE) {
die ("Mysql Error: " . $conn->error);
}
$stmt->bind_param("sis", $log, $code, $location);
$location = $_SERVER['REQUEST_URI'];
$stmt->execute();
$stmt->close();
die(json_encode($arr));
}
function alphanumeric($raw){
return preg_replace("/[^a-zA-Z0-9]+/", "", $raw);
}
function success(){
header("HTTP/1.0 200 Success");
$arr = array("Success");
die(json_encode($arr));
}
?>