Esempio n. 1
0
            switch ($op) {
                case "login":
                    // do some stuff
                    if (login($db, $_POST['username'], $_POST['userID']) == 200) {
                        $result = array("response" => 'User created!');
                        sendResponse(200, json_encode($result));
                        return true;
                    } else {
                        $result = array("response" => 'Server error: unable to create user');
                        sendResponse(500, json_encode($result));
                        return true;
                    }
                    break;
                default:
                    break;
            }
            $result = array("response" => 'Invalid request. Not a valid operation.');
            sendResponse(400, json_encode($result));
            return false;
        } catch (Exception $e) {
            $error = array("response" => 'failure', "message" => 'Server exception: ' . $e->getMessage());
            sendResponse(500, json_encode($error));
            return false;
        }
    }
}
// This is the first thing that gets called when this page is loaded
// Creates a new instance of the BaseAPI class and calls the doWork method
$api = new BaseAPI();
$api->doWork();