Skip to content

Instantly share code, notes, and snippets.

@wheech-lv
Created February 23, 2024 08:49
Show Gist options
  • Save wheech-lv/93260818143182b0281905ddaac3fe6b to your computer and use it in GitHub Desktop.
Save wheech-lv/93260818143182b0281905ddaac3fe6b to your computer and use it in GitHub Desktop.
Php script for purging Cloudflare DNS Records of a zone
$zone = 'zone_id'; // find it at https://api.cloudflare.com/client/v4/zones/
$apiToken = 'secret_token';
$apiUrl = "https://api.cloudflare.com/client/v4/zones/$zone/dns_records";
$ch = curl_init($apiUrl);
$user_email = '[email protected]';
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-Auth-Key: $apiToken",
"X-Auth-Email: $user_email"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
// var_dump($responseData);
$records = $responseData['result'];
foreach ($records as $record) {
$id = $record['id'];
$url = "https://api.cloudflare.com/client/v4/zones/$zone/dns_records/$id";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-Auth-Key: $apiToken",
"X-Auth-Email: $user_email"
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response, true);
var_dump($response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment