PHP code example of rahulmukati / hetzner-dns

1. Go to this page and download the library: Download rahulmukati/hetzner-dns library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rahulmukati / hetzner-dns example snippets


// If you installed via composer, just use this code to espace
use HetznerDNS\HetznerDNS;

// Initialize
$hdns = new HetznerDNS([
  'api_token' => 'YOURAPITOKENHERE'
]);

$hdns->createZone([
  'name' => 'example.com', //Required: String
  'ttl' => '3600' //Optional: Integer
]);

$body = '$ORIGIN example.com.
$TTL 3600
; SOA Records
@		IN	SOA	ns1.yourdomain.com. dns.yourdomain.com. 2020081403 86400 10800 3600000 3600
; NS Records
@		IN	NS	ns1.yourdomain.com.
@		IN	NS	ns2.yourdomain.com.
; A Records
@		IN	A	192.168.1.1
; CNAME Records
www		IN	CNAME	example.com.';

$hdns->importZoneFile('ZoneIDHere', $body);

$hdns->exportZoneFile('ZoneIDHere');

$hdns->getZones([
  'name' => '', //Optional: String
  'page' => '', //Optional: Number >= 1
  'per_page' => '', //Optional: Number <= 100
  'search_name' => '', //Optional: String
]);

$hdns->getZone('ZoneIDHere');

$hdns->updateZone('ZoneIDHere', [
  'name' => 'example.com', //Required: String
  'ttl' => '3600' //Optional: Integer
]);

$hdns->deleteZone('ZoneIDHere');

$hdns->createRecord([
  'zone_id' => 'ZoneIDHere', //Required: String
  'name' => '@', //Required: String
  'type' => 'CNAME', //Required: String ("A" "AAAA" "NS" "MX" "CNAME" "RP" "TXT" "SOA" "HINFO" "SRV" "DANE" "TLSA" "DS" "CAA")
  'value' => 'example.com', //Required
  'ttl' => '3600' //Optional: Integer
]);

$hdns->getRecords([
  'zone_id' => 'ZoneIDHere', //Optional: String
  'page' => '1', //Optional: Number
  'per_page' => '10', //Optional: Number
]);

$hdns->getRecord('RecordIDHere');

$hdns->updateRecord('RecordIDHere', [
  'zone_id' => 'ZoneIDHere', //Required: String (ID of zone this record is associated with)
  'name' => '@', //Required: String
  'type' => 'CNAME', //Required: String ("A" "AAAA" "NS" "MX" "CNAME" "RP" "TXT" "SOA" "HINFO" "SRV" "DANE" "TLSA" "DS" "CAA")
  'value' => 'example.com', //Required
  'ttl' => '3600' //Optional: Integer
]);

$hdns->deleteRecord('RecordIDHere');