/** * Register a new domain * * @param string $domain The domainname that needs to be registered * @param array $nameservers The nameservers for the new domain * @param Whois $whois The customer information for the domain's whois information * * @return bool * * @throws Api_Odr_Exception */ public function registerDomain($domain, $nameservers = array(), $whois = null, $isTest = false) { if (!$this->_checkLogin()) { return false; } $exploded = explode('.', $domain, 2); $tld = $exploded[1]; $ownerHandle = $this->_obtainHandle($domain, $whois, HANDLE_OWNER, $isTest); if (!$ownerHandle) { return $ownerHandle; } $adminHandle = $this->_obtainHandle($domain, $whois, HANDLE_ADMIN); if (!$adminHandle) { return $adminHandle; } $techHandle = $this->_obtainHandle($domain, $whois, HANDLE_TECH); if (!$techHandle) { return $techHandle; } $this->_checkPeriod($tld); $period = $this->Period * 12; $parameters = array('period' => $period, 'contact_registrant' => $ownerHandle, 'contact_tech' => $techHandle, 'contact_onsite' => $adminHandle, 'auth_code' => substr(md5(time()), 0, 6)); $parameters = array_merge($parameters, $this->convertNameservers($domain, $nameservers)); try { $this->odr->registerDomain($domain, $parameters); } catch (Api_Odr_Exception $e) { $this->Error[] = $e->getMessage(); return false; } return $this->_checkResult(true); }
// Configuration array, with user API Keys $config = array('api_key' => '#API_KEY#', 'api_secret' => '#API_SECRET#'); // Domain name that you want to register $domainName = 'test.nl'; // We assume that user already sent all the data to us through request $data = $_REQUEST; // Create new instance of API demo class $demo = new Api_Odr($config); // Login into API $demo->login(); $loginResult = $demo->getResult(); if ($loginResult['status'] === Api_Odr::STATUS_ERROR) { echo 'Can\'t login, reason - ' . $loginResult['response']; exit(1); } // Create new domain, by passing request data $demo->registerDomain($domainName, $data); // Get result of request $result = $demo->getResult(); if ($result['status'] !== Api_Odr::STATUS_SUCCESS) { echo 'Following error occurred: ' . (is_array($result['response']) ? $result['response']['message'] : $result['response']); if (!empty($result['response']['data'])) { foreach ($result['response']['data'] as $name => $error) { echo "\r\n\t{$name}: {$error}"; } } exit(1); } $result = $result['response']; // Domain successfully created, sploosh! echo 'Domain "' . $result['domain_name'] . '" created';
<?php // Require ODR API demo class require_once '../Api/Odr.php'; // Configuration array, with user API Keys $config = array('api_key' => '#API_KEY#', 'api_secret' => '#API_SECRET#'); // We assume that user already sent all the data to us through request $data = $_REQUEST; // Create new instance of API demo class $demo = new Api_Odr($config); // Login into API $demo->login(); $loginResult = $demo->getResult(); if ($loginResult['status'] === 'error') { echo 'Can\'t login, reason - ' . $loginResult['response']; exit(1); } // Create new domain, by passing request data $demo->registerDomain('test.nl', $data); // Get result of request $result = $demo->getResult(); if ($result['status'] !== 'success') { echo 'Following error occured: ' . $result['response']; exit(1); } $result = $result['response']; // Domain successfully created, sploosh! echo 'Domain "' . $result['domain_name'] . '" created';