$handle]; $data = ['query' => $query, 'variables' => $variables]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Content-Length: ' . strlen(json_encode($data)) ]); $result = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($result === FALSE || $httpcode != 200) { return ['error' => 'Failed to fetch data from LeetCode.']; } $profileData = json_decode($result, true); if (isset($profileData['errors']) || !isset($profileData['data']['matchedUser']) || $profileData['data']['matchedUser'] === null) { return ['error' => 'User not found or API error.']; } return $profileData['data']['matchedUser']; } ?>