- php-cli (v7.0 or newer)
This creates a new instance of the ZoneFile object.
domain- the domain the zone file is being generated for. This must be a fully qualified domain name that ends with a period (i.e.example.com.)ttl(optional) - the time to live (TTL), in seconds, that will be used for records where a TTL is not specified. The default value is60
<?php
require('ZoneFile.php');
$zone_file = new \evan_klein\zone_file\ZoneFile('example.com.', 240);
?>This method adds an A record to the zone.
name- the host name. This can be a relative host name (i.e.www) or a fully qualified domain name that ends with a period (i.e.www.example.com.)ipv4_addr- the IPv4 addressttl(optional) - the time to live (TTL), in seconds, for the record. If not specified, the zone file's defaultttlwill be used
<?php
require('ZoneFile.php');
$zone_file = new \evan_klein\zone_file\ZoneFile('example.com.', 240);
$zone_file->addA('example.com.', '93.184.216.34', 120);
$zone_file->addA('www', '93.184.216.34', 180);
$zone_file->addA('www1.example.com.', '93.184.216.34');
?>This method adds an AAAA record to the zone.
name- the host name. This can be a relative host name (i.e.www) or a fully qualified domain name that ends with a period (i.e.www.example.com.)ipv6_addr- the IPv6 addressttl(optional) - the time to live (TTL), in seconds, for the record. If not specified, the zone file's defaultttlwill be used
<?php
require('ZoneFile.php');
$zone_file = new \evan_klein\zone_file\ZoneFile('example.com.', 240);
$zone_file->addAAAA('example.com.', '2606:2800:220:1:248:1893:25c8:1946', 120);
$zone_file->addAAAA('www', '2606:2800:220:1:248:1893:25c8:1946', 180);
$zone_file->addAAAA('www1.example.com.', '2606:2800:220:1:248:1893:25c8:1946');
?>This method adds a CNAME record to the zone.
name- the host name. This can be a relative host name (i.e.www) or a fully qualified domain name that ends with a period (i.e.www.example.com.)cname- the host name. This can be a relative host name (i.e.www) or a fully qualified domain name that ends with a period (i.e.www.example.com.)ttl(optional) - the time to live (TTL), in seconds, for the record. If not specified, the zone file's defaultttlwill be used
<?php
require('ZoneFile.php');
$zone_file = new \evan_klein\zone_file\ZoneFile('example.com.', 240);
$zone_file->addCNAME('www', 'www1', 180);
$zone_file->addCNAME('www2.example.com.', 'www3');
$zone_file->addCNAME('www4', 'www5.example.com.');
?>This method adds a TXT record to the zone.
name- the host name. This can be a relative host name (i.e.www) or a fully qualified domain name that ends with a period (i.e.www.example.com.)data- the datattl(optional) - the time to live (TTL), in seconds, for the record. If not specified, the zone file's defaultttlwill be used
<?php
require('ZoneFile.php');
$zone_file = new \evan_klein\zone_file\ZoneFile('example.com.', 240);
$zone_file->addTXT('example.com.', 'key=value', 120);
$zone_file->addTXT('www', 'key=value', 180);
$zone_file->addTXT('www1.example.com.', 'key=value');
?>This method adds a MX record to the zone.
name- the host name. This can be a relative host name (i.e.mail) or a fully qualified domain name that ends with a period (i.e.example.com.)pri- the MX record's priority. The lower the number, the higher the priorityserver- the host name of the mail server. This can be a relative host name (i.e.mail) or a fully qualified domain name that ends with a period (i.e.mail.example.com.)ttl(optional) - the time to live (TTL), in seconds, for the record. If not specified, the zone file's defaultttlwill be used
<?php
require('ZoneFile.php');
$zone_file = new \evan_klein\zone_file\ZoneFile('example.com.', 240);
$zone_file->addMX('example.com.', 10, 'mail', 120);
$zone_file->addMX('example.com.', 10, 'mail1.example.com.');
$zone_file->addMX('example.com.', 20, 'mail2.example.com.');
?>This method adds a SRV record to the zone.
service- the service name (i.e.imap,imaps,pop3,pop3s, etc)protocol- the transport protocol (i.e.tcporudp)name- the host name. This can be a relative host name (i.e.imaps) or a fully qualified domain name that ends with a period (i.e.imaps.example.com.)pri- the SRV record's priority. The lower the number, the higher the priorityweight- the relative weight for records with the same priority. Records with higher weight are more likely to be chosenport- the port on which the service is runningtarget- the host name of the server providing the service. This can be a relative host name (i.e.imaps), a fully qualified domain name that ends with a period (i.e.imaps.example.com.), or a period (i.e..) if the service is not offered (i.e. for unencrypted services likeimaporpop3)ttl(optional) - the time to live (TTL), in seconds, for the record. If not specified, the zone file's defaultttlwill be used
<?php
require('ZoneFile.php');
$zone_file = new \evan_klein\zone_file\ZoneFile('example.com.', 240);
$zone_file->addSRV('submission', 'tcp', 0, 1, 587, 'smtp.example.com.', 60);
$zone_file->addSRV('imaps', 'tcp', 0, 1, 993, 'imap.example.com.', 120);
$zone_file->addSRV('pop3s', 'tcp', 10, 1, 995, 'pop.example.com.');
$zone_file->addSRV('jmap', 'tcp', 0, 1, 443, 'jmap.example.com.');
$zone_file->addSRV('carddavs', 'tcp', 0, 1, 443, 'carddav.example.com.');
$zone_file->addSRV('caldavs', 'tcp', 0, 1, 443, 'caldav.example.com.');
?>This method adds a NS record to the zone.
ns- the host name of the name server. This must be a fully qualified domain name that ends with a period (i.e.ns.nameserver.com.)ttl(optional) - the time to live (TTL), in seconds, for the record. If not specified, the zone file's defaultttlwill be used
<?php
require('ZoneFile.php');
$zone_file = new \evan_klein\zone_file\ZoneFile('example.com.', 240);
$zone_file->addNS('example.com.', 'ns.nameserver.com.', 120);
?>Outputs the zone file.
<?php
require('ZoneFile.php');
$zone_file = new \evan_klein\zone_file\ZoneFile('example.com.', 180);
$zone_file->addA('www', '93.184.216.34', 120);
$zone_file->addAAAA('www', '2606:2800:220:1:248:1893:25c8:1946', 120);
echo $zone_file->output();
?>The code above generates the output below:
$ORIGIN example.com.
$TTL 180
;example.com.
www 120 IN A 93.184.216.34
www 120 IN AAAA 2606:2800:220:1:248:1893:25c8:1946