A standalone, fully documented, bugless, fast and super easy to use PHP SDK for registering domain names.
Set $ns_key
to your api key provided by namesilo and then include namesilo.php in your application.
In namesilo.php file set your api key:
$ns_key = 'your api key goes here';
To receive a sandbox API key for testing, please contact namesilo.
For development edit namesilo.php and set
$ns_url = 'http://sandbox.namesilo.com/api/';
For production set
$ns_url = 'https://www.namesilo.com/api/';
To enable debugging edit namesilo.php and set $ns_debug to true.
$ns_debug = true;
Once enabled, all ns_*
functions print_r()
their request and return value.
never turn debugging on in production.
Retrieve the lock status for exmaple.com
$lock_status = ns_lock_status('example.com');
if($lock_status)
echo 'domain is lock';
else
echo 'domain is unlock';
Locking example.com:
$result = ns_domain_lock('example.com'); // attempt to lock exmaple.com
if($result){
echo 'Successfully locked the domain.';
}else{
echo 'The reason it failed: ' . $ns_error;
}
ns_domain_lock() retruns true on success and false on failure.
$ns_error is a global variable set by ns_domain_lock()
if you call ns_domain_lock() inside another function make sure to define $ns_error as a global variable global $ns_error;
- ns_create_contact(): create a new contact id. Used for new domain registration.
- ns_delete_contact(): useful for deleting a contact if registration fails
- ns_register_domain_by_contact_id()
- ns_register_domain(): create a new contact id and register domain at once (not recommended)
- ns_update_nameservers()
- ns_update_contact_by_domain()
- ns_add_dns_record()
- ns_get_dns_records(): returns an array of dns records
- ns_delete_dns_record()
- ns_is_domain_available()
- ns_send_auth_code(): Have the EPP transfer code for the domain emailed to the administrative contact.
- ns_get_contact_by_id()
- ns_list_domains()
- ns_get_nameservers()
- ns_privacy_status()
- ns_add_privacy()
- ns_remove_privacy()
- ns_get_domain_info()
- ns_get_account_balance()
returns created contact id on success and false on failure.
$contact_id = ns_create_contact(
$fn, // first name
$ln, // last name
$ad, // address
$cy, // city
$st, // state
$zp, // zip
$ct, // country
$em, // email
$ph // phone
);
if($contact_id){
echo 'new contact id: ' . $contact_id;
}else{
echo 'could not create contact id because: ' . $ns_error;
}
$result = ns_register_domain_by_contact_id($domain,$contact_id,$years=1);
if($result){
echo 'success';
}else{
echo 'fail reason: ' . $ns_error;
}
This function will automatically attemp to delete the contact if registration fails.
Please remember that the only contact profiles that can be deleted are those that are not the account default and are not associated with any active domains or order profiles.#### ns_register_domain() Create a new contact-id and register a domain for it at once. This method is not recommended.
returns created contact id on success and false on failure.
$result = ns_register_domain(
$domain, // example.com
$fn, // first name
$ln, // last name
$ad, // address
$cy, // city
$st, // state
$zp, // zip
$ct, // country
$em, // email
$ph, // phone
$years = 1
);
if($contact_id){
echo 'success';
}else{
echo 'failure reason: ' . $ns_error;
}
$result = ns_update_contact_by_domain(
$domain, // example.com
$fn, // first name
$ln, // last name
$ad, // address
$cy, // city
$st, // state
$zp, // zip
$ct, // country
$em, // email
$ph // phone
);
if($contact_id){
echo 'Success';
}else{
echo 'failure reason: ' . $ns_error;
}
$result = ns_update_nameservers('example.com','ns1.namesilo.com','ns2.namesilo.com');
if($result){
echo 'success';
}else{
echo 'fail reason: ' . $ns_error;
}
$result = ns_delete_contact($contact_id);
if($result){
echo 'success';
}else{
echo 'fail reason: ' . $ns_error;
}
#### ns_add_dns_record() > returns true on success and false on failure.Please remember that the only contact profiles that can be deleted are those that are not the account default and are not associated with any active domains or order profiles.
$result = ns_add_dns_record($domain,$type,$host,$value,$distance='',$ttl='');
if($result){
echo 'success';
}else{
echo 'fail reason: ' . $ns_error;
}
$type possible values are "A", "AAAA", "CNAME", "MX" and "TXT"
$host The hostname for the new record (there is no need to include the ".DOMAIN")
$value
- A - The IPV4 Address
- AAAA - The IPV6 Address
- CNAME - The Target Hostname
- MX - The Target Hostname
- TXT - The Text
$distance: Only used for MX (default is 10 if not provided)
$ttl: The TTL for the new record (default is 7207 if not provided)#### ns_get_dns_records() > returns an array of records on success and false on failure.
$result = ns_get_dns_records($domain);
if($result){
echo 'success';
}else{
echo 'fail reason: ' . $ns_error;
}
Sample print_r()
of successfull return value:
Array
(
[0] => Array
(
[record_id] => a8c4251d3c3d114d70d48dcaf0288257
[type] => A
[host] => sunsed-test15.com
[value] => 173.255.255.106
[ttl] => 7200
[distance] => 0
)
)
returns true on success and false on failure.
$result = ns_delete_dns_record($domain,$record_id);
if($result){
echo 'success';
}else{
echo 'fail reason: ' . $ns_error;
}
possible return values: 'available', 'invalid', 'unavailable' and false.
$result = ns_is_domain_available($domain);
if($result == 'available'){
echo 'domain is available';
}elseif($result == 'invalid'){
echo 'pleas check your domain';
}elseif($result == 'unavailable'){
echo 'domain is not available';
}else{
echo 'fail reason: ' . $ns_error;
}
returns true on success and false on failure.
$result = ns_send_auth_code($domain);
if($result){
echo 'success';
}else{
echo 'fail reason: ' . $ns_error;
}
returns contact info on success and false on failure.
$result = ns_get_contact_by_id($contact_id);
if($result){
echo 'success';
}else{
echo 'fail reason: ' . $ns_error;
}
returns an array of domains on success and false on failure.
$result = ns_list_domains();
if($result){
echo 'success';
}else{
echo 'fail reason: ' . $ns_error;
}
Sample return value:
Array
(
[0] => sunsed-test12.com
[1] => sunsed-test13.com
[2] => sunsed-test15.com
)
returns an array of nameservers on success and false on failure.
$result = ns_get_nameservers($domain);
if($result){
echo 'success';
}else{
echo 'fail reason: ' . $ns_error;
}
Sample return value:
Array
(
[0] => NS1.NAMESILO.COM
[1] => NS2.NAMESILO.COM
)
#### ns_privacy_status() Retrieves the privacy status.Namesilo returns the namesevrers in capital letters.
$result = ns_privacy_status($domain);
if($result)
echo 'Privacy is enabled';
else
echo 'Privacy is disabled';
$result = ns_add_privacy($domain);
if($result)
echo 'Privacy enabled';
else
echo 'could not add privacy because: ' . $ns_error;
$result = ns_remove_privacy($domain);
if($result)
echo 'Privacy disabled';
else
echo 'could not disable privacy because: ' . $ns_error;
$result = ns_get_domain_info($domain);
if($result)
echo 'success';
else
echo 'failed because because: ' . $ns_error;
Sample return value:
Array
(
[code] => 300
[detail] => success
[created] => 2015-02-06
[expires] => 2016-02-06
[status] => Active
[locked] => Yes
[private] => Yes
[auto_renew] => No
[traffic_type] => Custom DNS
[forward_url] => N/A
[forward_type] => N/A
[nameservers] => Array
(
[nameserver] => Array
(
[0] => NS1.NAMESILO.COM
[1] => NS2.NAMESILO.COM
)
)
[contact_ids] => Array
(
[registrant] => 903
[administrative] => 903
[technical] => 903
[billing] => 903
)
)
$result = ns_get_account_balance();
if($result)
echo 'success';
else
echo 'failed because because: ' . $ns_error;
Send message to @seyedip
Be happy,
Sed