Skip to content

Instantly share code, notes, and snippets.

@u7ter
Created April 28, 2020 10:16
Show Gist options
  • Select an option

  • Save u7ter/d7bb7c6974558a8738e06066fec49353 to your computer and use it in GitHub Desktop.

Select an option

Save u7ter/d7bb7c6974558a8738e06066fec49353 to your computer and use it in GitHub Desktop.
edit Dns Cloudflare api
<?
/**
mydomain.com
stage.mydomain.com edit to new ip
*/
require_once('vendor/autoload.php');
$key = new \Cloudflare\API\Auth\APIKey('mail@gmail.com', 'key');
$adapter = new Cloudflare\API\Adapter\Guzzle($key);
$zones = new \Cloudflare\API\Endpoints\Zones($adapter);
$domains = [
'mydomain.com',
];
foreach ($domains as $domain) {
sleep(1);
try {
$zoneID = $zones->getZoneID($domain);
$dns = new \Cloudflare\API\Endpoints\DNS($adapter);
$recordID = $dns->getRecordID($zoneID, 'A', 'stage.' . $domain);
$r = $dns->updateRecordDetails($zoneID, $recordID, [
'type' => 'A',
'name' => 'stage.' . $domain,
'proxied' => true,
'content' => 'ip'
]);
print_r( $domain . ': ' . $r->success. "\n");
}catch (Exception $exception) {
print_r( $domain . ': ' . $exception->getMessage(). "\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment