• 17-10-2023, 20:06:07
    #1
    Arkadaşlar ilk önce https://dash.cloudflare.com/profile/api-tokens bu linkten global api key alınız daha sonra;

    <?php
    $apiKey = "cloudflareapikey";
    $email = "test@r10.net";
    $domain = "r10.net";
    $apiUrl = "https://api.cloudflare.com/client/v4/zones";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "{$apiUrl}?name={$domain}");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "X-Auth-Email: {$email}",
        "X-Auth-Key: {$apiKey}",
        "Content-Type: application/json"
    ));
    $response = curl_exec($ch);
    curl_close($ch);
    
    $zoneData = json_decode($response, true);
    
    if (isset($zoneData['success']) && $zoneData['success'] && isset($zoneData['result']) && count($zoneData['result']) > 0) {
        $zoneId = $zoneData['result'][0]['id'];
    
        // Zonun tüm DNS kayıtlarını çek
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "{$apiUrl}/{$zoneId}/dns_records");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "X-Auth-Email: {$email}",
            "X-Auth-Key: {$apiKey}",
            "Content-Type: application/json"
        ));
        $response = curl_exec($ch);
        curl_close($ch);
    
        $dnsRecords = json_decode($response, true);
    
        if (isset($dnsRecords['success']) && $dnsRecords['success'] && isset($dnsRecords['result']) && count($dnsRecords['result']) > 0) {
            foreach ($dnsRecords['result'] as $record) {
                // Her bir DNS kaydını sil
                $recordId = $record['id'];
    
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, "{$apiUrl}/{$zoneId}/dns_records/{$recordId}");
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    "X-Auth-Email: {$email}",
                    "X-Auth-Key: {$apiKey}",
                    "Content-Type: application/json"
                ));
                $response = curl_exec($ch);
                curl_close($ch);
    
                echo "DNS Record '{$record['name']}' deleted.\n";
            }
        } else {
            echo "No DNS records found for the zone.\n";
        }
    } else {
        echo "Zone not found.\n";
    }
    ?>
  • 17-10-2023, 20:09:04
    #2
    Curl olarak paylaşsanız daha iyi olurdu