$desc, "group" => $group, "id" => $ip, "type" => $selected_option ]; // Make API request $response = make_post_request($url, $data); if ($response === FALSE) { $response = json_encode(['status' => 'error', 'message' => 'An error occurred']); } // Decode response data $response_data = json_decode($response, true); // Handle different response statuses if ($response_data['status'] === 201) { $_SESSION['message'] = "Switch Created Successfully"; $redirect_page = "./switch.php"; } elseif ($response_data['status'] === 409) { $_SESSION['message'] = "Switch not created. IP Address already exists."; $redirect_page = "./new_switch.php"; } else { $_SESSION['message'] = $response_data['message'] ?? 'An unexpected error occurred.'; $redirect_page = "./switch.php"; } // Redirect to the appropriate page header('Location: ' . $redirect_page); exit(); } else { header('Location: ../index.php'); exit(); } } else { header('Location: ../index.php'); exit(); } ?>