3
3
4
4
header ('Content-Type: application/json ' ); // Server should always return json
5
5
6
- $ config = json_decode (file_get_contents ('/var/config/config.json ' ), true ); // We get the Database Information
6
+ // YOU CAN CHANGE THE LOCATION!! dont put it inside www or it will be exposed (You can also use a .htaccess to prevent that but is is your choice)
7
+ $ config = json_decode (file_get_contents ('/var/config/config.json ' ), true ); // We get the Database Information | Path is absolute!
8
+
9
+ if (!$ config ) {
10
+ sp (500 , 'Something failed, please check the docs again ' );
11
+ }
7
12
8
13
// We define a simple status response for the client
9
- if (isset ($ _GET ['status ' ])) {
14
+ if (isset ($ _GET ['status ' ])) {
10
15
sp (200 , 'Ok ' );
11
16
}
12
17
23
28
24
29
$ conn = new mysqli ($ config ['SQL_HOST ' ], $ config ['SQL_USER ' ], $ config ['SQL_PASS ' ], $ config ['SQL_DB ' ]);
25
30
if ($ conn ->connect_error ) {
26
- sp (500 , 'Something failed ' ,);
31
+ sp (500 , 'Something failed ' , );
27
32
}
28
33
29
34
// We now read the data sent from the client and store it in variables
60
65
$ data = FetchData ($ conn , $ userid );
61
66
sp (200 , 'Ok ' , $ data ['id ' ], $ data ['email ' ], $ data ['group_id ' ], $ data ['avatar ' ]);
62
67
} else {
63
- sp (403 , 'hwid_missmatch ' );
68
+ sp (403 , 'Invalid Information ' );
64
69
}
65
70
66
71
// Dont forget to db connection we opened at the beginning. This will prevent injection attacks and other stuff.
69
74
}
70
75
71
76
// DRY ;) We define a simple function that returns a json response to the client. We can also use this function to return a 500 error if something fails.
72
- function sp ($ code , $ status = '' , $ id = null , $ email = null , $ group_id = null , $ avatar = null ) {
77
+ function sp ($ code , $ status = '' , $ id = null , $ email = null , $ group_id = null , $ avatar = null )
78
+ {
73
79
http_response_code ($ code );
74
80
$ response = array (
75
81
'status ' => $ status ,
@@ -79,7 +85,7 @@ function sp($code, $status = '', $id = null, $email = null, $group_id = null, $a
79
85
$ response ['email ' ] = $ email ;
80
86
$ response ['group_id ' ] = $ group_id ;
81
87
$ response ['avatar ' ] = $ avatar ;
82
-
88
+
83
89
}
84
90
echo json_encode ($ response );
85
91
die ();
@@ -198,4 +204,4 @@ function FetchData($conn, $userid)
198
204
$ stmt ->close ();
199
205
return null ;
200
206
}
201
- }
207
+ }
0 commit comments