NOW() LIMIT 1"); // Failed if (mysqli_num_rows($sql) !== 1) { // Invalid Key $url_path = sanitizeInput(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH)); mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'API', log_action = 'Failed', log_description = 'Incorrect or expired key (endpoint: $url_path)', log_ip = '$ip', log_user_agent = '$user_agent'"); $return_arr['success'] = "False"; $return_arr['message'] = "Authentication failed. API key is invalid or has expired."; header(WORDING_UNAUTHORIZED); echo json_encode($return_arr); exit(); } else { // SUCCESS // Set client ID, company ID & key name $row = mysqli_fetch_array($sql); $api_key_name = htmlentities($row['api_key_name']); $api_key_decrypt_hash = $row['api_key_decrypt_hash']; // No sanitization $client_id = intval($row['api_key_client_id']); // Set limit & offset for queries if (isset($_GET['limit'])) { $limit = intval($_GET['limit']); } elseif (isset($_POST['limit'])) { $limit = intval($_POST['limit']); } else { $limit = 50; } if (isset($_GET['offset'])) { $offset = intval($_GET['offset']); } elseif (isset($_POST['offset'])) { $offset = intval($_POST['offset']); } else { $offset = 0; } } }