/** * @param string $type * @param string $message */ function APIResponse($type = RESPONSE_404, $message = null) { switch ($type) { case RESPONSE_200: case RESPONSE_404: case RESPONSE_401: case RESPONSE_400: case RESPONSE_500: header("Status: {$type}"); header('Cache-Control: max-age=30'); if (!is_null($message)) { if (!is_array($message)) { $message = array('message' => $message); } buildJSONResponse($message); } break; default: APIResponse(RESPONSE_500); break; } exit; }
function build404($request = false, $message = false, $exit = true) { $htmlMessage = $message ? "<br /><br /><pre>" . htmlspecialchars($message, ENT_QUOTES) . "</pre>" : false; if ($request === false) { global $url; if (!empty($url)) { $request = explode('/', $url); } } if (is_array($request)) { foreach ($request as $item) { switch ($item) { case REQUEST_TYPE_AJAX: buildJSONResponse(array('success' => false, 'message' => 'Error: Could not find the function ' . implode('/', $request))); exit; case REQUEST_TYPE_MODAL: include 'pages/components/modalHeader.php'; echo '<h1>Not Found</h1><p>The requested URL /' . implode('/', $request) . ' was not found on this server.</p><hr><address>Apache/2.2.14 (Ubuntu) Server at customintercept.com Port 80</address>' . $htmlMessage; include 'pages/components/modalFooter.php'; exit; } } header("HTTP/1.0 404 Not Found"); echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL /' . implode('/', $request) . ' was not found on this server.</p><hr><address>Apache/2.2.14 (Ubuntu) Server at customintercept.com Port 80</address>' . $htmlMessage . '</body></html>'; if ($exit) { exit; } } else { header("HTTP/1.0 404 Not Found"); echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL /' . $request . ' was not found on this server.</p><hr><address>Apache/2.2.14 (Ubuntu) Server at customintercept.com Port 80</address>' . $htmlMessage . '</body></html>'; if ($exit) { exit; } } }
/** * Return the error code in a JSON structure * code 1 : Check error * code 2 : Auth error * code 3 : Hierarchy error * code 4 : Malformed request */ function returnErrorCode($err_code) { return buildJSONResponse(array("create" => "erreur", "code" => $err_code)); }