Created
April 28, 2020 10:16
-
-
Save u7ter/d7bb7c6974558a8738e06066fec49353 to your computer and use it in GitHub Desktop.
edit Dns Cloudflare api
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
| <? | |
| /** | |
| 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