Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8405653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:53:51+00:00 2026-06-09T22:53:51+00:00

I modified the example script from the Plesk documentation to create an A-Name Record

  • 0

I modified the example script from the Plesk documentation to create an A-Name Record remotely, but gave up on it weeks ago as it was nothing but headaches. I have now started working on this again, but am now faced with the exact same problem. The example script comes filled with try/catch and error exceptions, but no matter what, all I get is a white page when I run the script.

I tried adding a bunch of echos to the document as well, but unless these are outside of the functions, they do not print out either. Am I just doing something very stupid or is there something I am missing with Plesk?

<?php

/** Reports error during API RPC request */
class ApiRequestException extends Exception {}

function DNSCreateRequest()
{
    $xmldoc = new DomDocument('1.0', 'UTF-8');
    $xmldoc->formatOutput = true;

    // <packet>
    $packet = $xmldoc->createElement('packet');
    $packet->setAttribute('version', '1.6.3.0');
    $xmldoc->appendChild($packet);

    // <packet/dns>
    $dns = $xmldoc->createElement('dns');
    $packet->appendChild($dns);

    // <packet/dns/add_rec>
    $addrec = $xmldoc->createElement('add_rec');
    $dns->appendChild($addrec);

    // add_rec elements
    $addrec->appendChild($xmldoc->createElement('domain_name','domain.net'));
    $addrec->appendChild($xmldoc->createElement('type','A'));
    $addrec->appendChild($xmldoc->createElement('host','testdns'));
    $addrec->appendChild($xmldoc->createElement('value','127.0.0.1'));

    return $xmldoc;
}

/** Prepares CURL to perform the Panel API request */
function curlInit($host, $login, $password)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://{$host}:8443/enterprise/control/agent.php");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST,           true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_HTTPHEADER,
    array("HTTP_AUTH_LOGIN: {$login}",
        "HTTP_AUTH_PASSWD: {$password}",
        "HTTP_PRETTY_PRINT: TRUE",
        "Content-Type: text/xml")
    );

    return $curl;
}

/** Performs a Panel API request, returns raw API response text */
function sendRequest($curl, $packet)
{
    curl_setopt($curl, CURLOPT_POSTFIELDS, $packet);
    $result = curl_exec($curl);

    if (curl_errno($curl))
    {
        $errmsg  = curl_error($curl);
        $errcode = curl_errno($curl);
        echo "error message: " . $errmsg;
        echo "error code: " . $errcode;
        curl_close($curl);
        throw new ApiRequestException($errmsg, $errcode);
    }

      curl_close($curl);
      return $result;
}

/** Looks if API responded with correct data */
function parseResponse($response_string)
{
    $xml = new SimpleXMLElement($response_string);

    if (!is_a($xml, 'SimpleXMLElement'))
    {
        echo "Cannot parse server response: " . $response_string;
        throw new ApiRequestException("Cannot parse server response: {$response_string}");
    }

    return $xml;
}

/** Check data in API response */
function checkResponse(SimpleXMLElement $response)
{
    $resultNode = $response->dns->add_rec->result;

    // check if request was successful
    if ('error' == (string)$resultNode->status)
    {
        echo "The Panel API returned an error: " . (string)$resultNode->result->errtext;
        throw new ApiRequestException("The Panel API returned an error: " . (string)$resultNode->result->errtext);
    }
}

// int main()
$host = 'www.hostname.com';
$login = 'admin_user';
$password = '$password$';

$curl = curlInit($host, $login, $password);

try
{
    $response = sendRequest($curl, DNSCreateRequest()->saveXML());
    $responseXml = parseResponse($response);
    checkResponse($responseXml);
}
catch (ApiRequestException $e)
{
    echo $e;
    die();
}

// Explore the result
foreach ($responseXml->xpath('/packet/dns/add_rec/result') as $resultNode)
{
    echo "DNS id: " . (string)$resultNode->id . " ";
    //echo (string)$resultNode->data->gen_info->name . " (" . (string)$resultNode->data->gen_info->dns_ip_address . ")\n";
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:53:52+00:00Added an answer on June 9, 2026 at 10:53 pm

    Thanks to rdo’s comment, I was able to determine that it would not accept “domain_name” and instead wanted a “site-id” instead. Once this was used, my script worked flawlessly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an example from a book, a bit modified. It seems like sessions
I must copy a <script> node from xml to html, but I need to
Firstly, the Google Chart API example from Google (it is javascript) actually <script type=text/javascript>
I modified an example with threads and got the example with multiprocessing included below.
I've slightly modified the iPhone SDK's GLSprite example while learning OpenGL ES and it
I'm doing an xpinc application. I followed the example in here and modified it.
I have modified a slider script to mimic ebay's slider on home page. I
Hi I am using some modified code from another post. Basically I want to
I'm having an issue accessing raw request information from PHP when accessing a script
I need a little help with a script i modified. I've created a submenu

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.