-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathindex.php
More file actions
53 lines (46 loc) · 1.26 KB
/
index.php
File metadata and controls
53 lines (46 loc) · 1.26 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
<?php
/**
* Simple example of web service
* @author R. Bartolome
* @version v1.0
* @return JSON messages with the format:
* {
* "code": mandatory, string '0' for correct, '1' for error
* "message": empty or string message
* "data": empty or JSON data
* }
*
* This file can be tested from the browser:
* http://localhost/webservice-php-json/service_test.php
*
* Based on
* http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app
*/
// the API file
require_once 'api.php';
// creates a new instance of the api class
$api = new api();
// message to return
$message = array();
switch($_POST["action"])
{
case 'get':
$params = array();
$params['id'] = isset($_POST["id"]) ? $_POST["id"] : '';
if (is_array($data = $api->get($params))) {
$message["code"] = "0";
$message["data"] = $data;
} else {
$message["code"] = "1";
$message["message"] = "Error on get method";
}
break;
default:
$message["code"] = "1";
$message["message"] = "Unknown method " . $_POST["action"];
break;
}
//the JSON message
header('Content-type: application/json; charset=utf-8');
echo json_encode($message, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHED);
?>