Skip to content

Instantly share code, notes, and snippets.

@maietta
Created June 13, 2016 21:15
Show Gist options
  • Save maietta/af68a9eeabe139b4a0cd1250c947bf8c to your computer and use it in GitHub Desktop.
Save maietta/af68a9eeabe139b4a0cd1250c947bf8c to your computer and use it in GitHub Desktop.
CloudFlare PHP Sample Get Fresh list of DNS Zones
<?php
header("Content-Type: application/json");
$curl = curl_init();
$query_array = array(
"a"=>"zone_load_multi"
,"tkn"=>"8fd535bb...11dbbcdab"
,"email"=>"user@domain.tld"
);
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1
, CURLOPT_URL => 'https://www.cloudflare.com/api_json.html?'. http_build_query($query_array)
// , CURLOPT_USERAGENT => 'My App - CF::GetFresherListOfZones'
));
$json = (object) json_decode(curl_exec($curl), true);
curl_close($curl);
$zones = (object) $json->response['zones'];
$count = (string) $json->response['zones']['count'];
$objs = $json->response['zones']['objs'];
for ($i = 0; $i<$count; $i++) {
$zone = (object) $objs[$i];
$domains[] = $zone->zone_name;
}
ksort($domains);
$domains = json_encode($domains, true);
file_put_contents("~/portals.json", $domains);
echo $domains;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment