3 // @see https://www.php.net/manual/en/session.configuration.php
4 ini_set("session.use_cookies", 0);
5 ini_set("session.use_only_cookies", 0);
6 ini_set("session.use_trans_sid", 0);
7 ini_set("session.cache_limiter", "");
8 session_id('dummy-session-id');
11 // Response 'Content-Type' header
12 header('Content-Type: application/json');
14 // Flag that tells if the 'Accept' header in the request is invalid
15 $invalidAccept = '*/*' != $_SERVER['HTTP_ACCEPT'] && 'application/json' != $_SERVER['HTTP_ACCEPT'];
17 // Do not accept requests which 'Accept' header isn't one of the above
19 header('HTTP/1.1 406 Not Acceptable');
23 // Get request method and path
24 $method = strtolower($_SERVER['REQUEST_METHOD']);
25 $uri = parse_url($_SERVER['REQUEST_URI']);
26 $path = trim(trim($uri['path']), '/');
28 // Default 'resource' and 'id' values
32 // Get 'resource' and 'id' values
34 $path = explode('/', $path);
36 if (!empty($path[1])) {
41 // Default 'input' value
45 if ('post' == $method ||
'put' == $method) {
46 $input = file_get_contents('php://input');
49 // File name (convention) from where the logic will be loaded
50 $fileName = strtolower("{$method}_{$resource}");
51 $fileName.= $id ?
'_id' : '';
54 // Function name (convention) that handles the request
56 // The function will receive the following parameters:
58 // * Parameter 1: int|null $id The item ID (if it's present)
59 // * Parameter 2: string|null $input The input value (if it's present)
60 $functionName = 'handle_request';
62 // Load and call the logic that handles the request
63 if (is_readable($fileName)) {
64 require_once($fileName);
65 if (function_exists($functionName)) {
66 $functionName($id, $input);
71 // Default (404) response code
72 header('HTTP/1.1 404 Not Found');