-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhelpers.php
51 lines (32 loc) · 953 Bytes
/
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
48
49
50
51
<?php
// function to replace last occurence
function str_replace_last( $search , $replace , $str ) {
if( ( $pos = strrpos( $str , $search ) ) !== false ) {
$search_length = strlen( $search );
$str = substr_replace( $str , $replace , $pos , $search_length );
}
return $str;
}
// function to get request parameters
function getRequestParams() {
$requestArgs = new stdClass();
$requestArgs->type = $_GET["type"];
$requestArgs->id = $_GET["id"];
if (isset($_GET["extra"])) {
parse_str($_GET["extra"], $requestArgs->extra);
$requestArgs->extra = (object) $requestArgs->extra;
}
return $requestArgs;
}
function setHeaders() {
// enable CORS
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
// set JSON content-type
header("Content-Type: application/json");
}
function page404() {
header("HTTP/1.1 404 Not Found");
echo "404 Page Not Found";
}
?>