Created
June 13, 2016 21:15
-
-
Save maietta/af68a9eeabe139b4a0cd1250c947bf8c to your computer and use it in GitHub Desktop.
CloudFlare PHP Sample Get Fresh list of DNS Zones
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Content-Type: application/json"); | |
$curl = curl_init(); | |
$query_array = array( | |
"a"=>"zone_load_multi" | |
,"tkn"=>"8fd535bb...11dbbcdab" | |
,"email"=>"[email protected]" | |
); | |
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