API Documentation RunningExamples server.ipv6addr get reverse PHP

Aus EUserv Wiki

Version vom 10:17, 17. Sep. 2012 bei Praktikant3 (Diskussion | Beiträge)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

server.ipv6addr_get_reverse

<?php

//includes the class library
include_once("xmlrpc.inc");
$xmlrpc_internalencoding = 'UTF-8';

$host="api.test.euserv.net";
$port=443;
$username="<API_USER>";
$password="<API_USER_PASSWORD>";
$api_path="/";
$srv_id=1337;
$ipv6_address= "<IPv6 address>";

//defines the function
function server_ipv6addr_get_reverse($host,$port,$username,$password,$api_path,$srv_id,$ipv6_address)
{
	//creates the serverurl
	$serverurl = 'https://'.$host.':'.$port.'/'.$api_path;


	//----------creates the message which will be send to the server----------

	//creates the request for the XML-RPC Server
	$request = new xmlrpcmsg('server.ipv6addr_get_reverse');

	//adds parameters to the request
	$request->addParam
	(
			//creates a value of type struct which contains an array with the username, password, server ID IPv6 address and reverse entry
			new xmlrpcval
			(
					array
					(
							//creates a value of type string which contains the "$username"
							'login' => new xmlrpcval($username, 'string'),

							//creates a value of type string which contains the "$password"
							'password' => new xmlrpcval($password, 'string'),

							//creates a value of type int which contains the "$srv_id"
							'srv_id' => new xmlrpcval($srv_id, 'int'),
								
							//creates a value of type string which contains the "$ipv6_address"
							'ipv6_address' => new xmlrpcval($ipv6_address, 'string')

					)
					,'struct'
			)
	);


	//----------creates the XML-RPC client which represent a client of an XML-RPC server----------

	//creates the client
	$client = new xmlrpc_client($serverurl);

	//disable SSL Keycheck
	$client->setSSLVerifyPeer(0);


	//----------sends the request to the server and gets the response----------

	//sends the request via https and writes it into $response. timeout is set to 0
	$response = $client->send($request,0,'https');

	//generates a storable representation of $response and writes it into $result_xml
	//$result_xml = $response->serialize();

	//checks the response. if the method "faultCode" returns zero, the response was succesfull
	if (0==$response->faultCode())
	{
		//returns the value sent by the server
		$value = $response->value();

		//returns the actual PHP-language value of "value"
		$result_obj = $value->scalarval();

		//destroys "value"
		unset($value);
	}
	else
	{
		//returns the faultCode and the faultString
		return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString());
	}

	//destroys "client"
	unset($client);

	//destroys "response"
	unset($response);


	//----------reads the result_obj----------

	//if result_obj is set then it returns the actual PHP-language value of "result_obj"
	if (isset($result_obj['status']))
	{
		$value['status'] = $result_obj['status']->scalarval();
	}

	if (isset($result_obj['ipv6_address']))
	{
		$value['ipv6_address'] = $result_obj['ipv6_address']->scalarval();
	}

	if (isset($result_obj['reverse_entry']))
	{
		$value['reverse_entry'] = $result_obj['reverse_entry']->scalarval();
	}

	return $value;
}

//calls the function
$result = server_ipv6addr_get_reverse($host, $port, $username, $password, $api_path, $srv_id,$ipv6_address);
if(0==$result['faultCode'])
{
	echo "Status: ".$result['status']."<br>";

	echo "IPv6 address: ".$result['ipv6_address']."<br>";

	echo "Reverse entry: ".$result['reverse_entry'];
}
else
{
	echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString'];
}

?>