$user_id = $logged_in_user['id']; // Decode json data $data = json_decode($_GET['data'], true); $method = $_GET['method']; // Call appropriate method if ($method == 'get_upcoming_drives') { return get_upcoming_drives($user_id, $data); } else { if ($method == 'get_requests_for_trip') { return get_requests_for_trip($user_id, $data); } else { if ($method == 'get_spots_remaining_for_trip') { return get_spots_remaining_for_trip($user_id, $data); } else { if ($method == 'get_rides') { return get_rides($user_id, $data); } else { return functions\json_respond('ERROR', 'Unknown method!'); } } } } } elseif ($_POST) { // Get logged in user $logged_in_user = user\get_logged_in_user(); if (!$logged_in_user) { return functions\json_respond('ERROR', 'Login required!'); } $user_id = $logged_in_user['id']; // Decode json data $data = json_decode($_POST['data'], true);
<?php require_once __DIR__ . '/mysql.php'; header('Content-Type: application/json; charset=utf-8'); ob_start(NULL, 0, PHP_OUTPUT_HANDLER_CLEANABLE); try { $response = get_rides(false); } catch (Exception $e) { echo $e->getMessage(); $response = ['error' => $e->getMessage()]; } ob_clean(); echo json_encode($response);