-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.php
More file actions
executable file
·81 lines (54 loc) · 1.83 KB
/
Copy pathapp.php
File metadata and controls
executable file
·81 lines (54 loc) · 1.83 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
<?php
namespace MzQ;
class app
{
public static function generateRandomString($length = 10)
{
$characters = '0123456789qwertyuiopasdfghjklzxcvbnm!@#$%^&*()';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
public static function hasKeys($json , $items) {
foreach ($items as $item) {
if(!isset($json->$item)) return false;
}
return true ;
}
public static function missingKeys($json , $items) {
$missing = array();
foreach ($items as $item) {
if(!isset($json->$item)) $missing[] = $item;
}
return $missing ;
}
public static function out($response , $HTTP_STATUS_CODE = HTTP_BAD_REQUEST , $ShaparakResponse = '', $system = false) {
if(is_array($response))
$res = array('Success' => $HTTP_STATUS_CODE==200) + $response;
else $res = array('Success' => $HTTP_STATUS_CODE==200, "Data" => $response) ;
if(!$system){
http_response_code($HTTP_STATUS_CODE);
}
if($system) return $res;
die(json_encode($res));
}
public static function outApi($response , $system = false) {
if($system) return $response;
die(json_encode($response));
}
public static function getUserIpAddr(){
if(!empty($_SERVER['HTTP_CLIENT_IP'])){
//ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
//ip pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
}