I have been working on a whois xml script that requests whois data from my service provider. Presently it is working no problem and returning the correct response. The only issue I have is that it doesnt return in a structured layout like so:
Whois Server Version 2.0 Domain names in the .com and .net domains can now be registered with many different competing registrars. Go to http://www.internic.net for detailed information. Domain Name: LYSAND.COM Registrar: TUCOWS INC. Whois Server: whois.tucows.com Referral URL:
This is my php>XML code below. Is there anyone that can help me understand how to get a reponse in a structured layout:
<?php include("../user.php"); ?>
<?php
error_reporting(0);
$whois = $_POST ['whois'];
$auth = $_POST ['auth'];
$request = construct_xml($whois, $auth, $authuser);
$response = whois($request);
$whoisoutput = parse_response($response);
if ($whoisoutput == 0) {
echo "$response\r\n\r\n <a href=\"#\" onclick=\"history.go(-1);return false;\">BACK</a>";
}
else {
echo "Oops something was wrong\n ";
}
function construct_xml ($whois, $auth, $authuser) {
return <<<XML
<?xml version='1.0' encoding='utf-8' ?>
<rpc module='Domain' method='Whois' version='1.0'>
<auth>
<username>$authuser</username>
<password>$auth</password>
</auth>
<whois datatype='whois'>$whois</whois>
</rpc>
XML;
}
function whois ($request) {
$header .= "POST / HTTP/1.0\r\n";
$header .= "Content-Type: text/xml\r\n";
$header .= "Content-Length: " . strlen($request) . "\r\n\r\n";
$fp = fsockopen("xmlrpc.myserver.co.uk", 282828, $errno, $errstr, 30);
if ($fp) {
fputs ($fp, $header . $request);
while (!feof($fp)) {
$response .= fgets($fp, 16728);
}
fclose ($fp);
$pos = strpos($response, "\r\n\r\n");
$response = substr($response, $pos + 4);
}
return $response;
}
function parse_response ($xml) {
$xml = new SimpleXMLElement($xml);
$code = $xml->response['code'];
$text = $xml->response['text'];
$string = $xml->response['datatype'];
if ($code != 0) {
echo "Error occurred: $text\n";
exit;
}
return $xml->output;
}
?>