API Documentation RunningExamples server.ipaddr get reverse PHP
Aus EUserv Wiki
(Unterschied zwischen Versionen)
Root (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „back to API Documentation <nowiki> <?php //includes the class library include_once("lib/xmlrpc.inc"); $xmlrpc_internalencoding = 'UTF-8'; $host="api.test.e…“) |
Root (Diskussion | Beiträge) |
||
(Der Versionsvergleich bezieht 1 dazwischenliegende Version mit ein.) | |||
Zeile 1: | Zeile 1: | ||
- | back to [[API Documentation]] | + | back to [[API_Documentation#PHP_EXAMPLE_9|API Documentation]] |
- | + | = server.ipaddr_get_reverse = | |
<nowiki> | <nowiki> | ||
<?php | <?php | ||
+ | |||
//includes the class library | //includes the class library | ||
include_once("lib/xmlrpc.inc"); | include_once("lib/xmlrpc.inc"); | ||
$xmlrpc_internalencoding = 'UTF-8'; | $xmlrpc_internalencoding = 'UTF-8'; | ||
+ | |||
$host="api.test.euserv.net"; | $host="api.test.euserv.net"; | ||
$port=443; | $port=443; | ||
Zeile 16: | Zeile 18: | ||
function server_ipaddr_get_reverse($host,$port,$username,$password,$api_path,$srv_id,$ip_address) | function server_ipaddr_get_reverse($host,$port,$username,$password,$api_path,$srv_id,$ip_address) | ||
{ | { | ||
- | //creates the serverurl | + | |
- | $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; | + | //creates the serverurl |
- | //----------creates the message which will be send to the server---------- | + | $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; |
- | //creates the request for the XML-RPC Server | + | |
- | $request = new xmlrpcmsg('server.ipaddr_get_reverse'); | + | //----------creates the message which will be send to the server---------- |
- | //adds parameters to the request | + | |
- | $request->addParam | + | //creates the request for the XML-RPC Server |
- | ( | + | $request = new xmlrpcmsg('server.ipaddr_get_reverse'); |
- | //creates a value of type struct which contains an array with the username and password | + | |
- | new xmlrpcval | + | //adds parameters to the request |
- | ( | + | $request->addParam |
- | array | + | ( |
- | ( | + | |
- | //creates a value of type string which contains the "$username" | + | //creates a value of type struct which contains an array with the username and password |
- | 'login' => new xmlrpcval($username, 'string'), | + | new xmlrpcval |
- | //creates a value of type string which contains the "$password" | + | ( |
- | 'password' => new xmlrpcval($password, 'string'), | + | array |
- | //creates a value | + | |
- | 'srv_id' => new xmlrpcval($srv_id, 'int'), | + | ( |
- | //creates a value | + | //creates a value of type string which contains the "$username" |
- | 'ip_address' => new xmlrpcval($ip_address, 'string'), | + | 'login' => new xmlrpcval($username, 'string'), |
- | ) | + | |
- | ,'struct' | + | //creates a value of type string which contains the "$password" |
- | ) | + | 'password' => new xmlrpcval($password, 'string'), |
- | ); | + | |
- | //----------creates the XML-RPC client which represent a client of an XML-RPC server---------- | + | //creates a value |
- | //creates the client | + | 'srv_id' => new xmlrpcval($srv_id, 'int'), |
- | $client = new xmlrpc_client($serverurl); | + | |
- | //disable SSL Keycheck | + | //creates a value |
- | $client->setSSLVerifyPeer(0); | + | 'ip_address' => new xmlrpcval($ip_address, 'string'), |
- | //----------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'); | + | ,'struct' |
- | //generates a storable representation of $response and writes it into $result_xml | + | ) |
- | //echo $response->serialize(); | + | ); |
- | //checks the response. if the method "faultCode" returns zero, the response was succesfull | + | |
- | if (0==$response->faultCode()) | + | //----------creates the XML-RPC client which represent a client of an XML-RPC server---------- |
- | { | + | |
- | //returns the value sent by the server | + | //creates the client |
- | $value = $response->value(); | + | $client = new xmlrpc_client($serverurl); |
- | //returns the actual PHP-language value of "value" | + | |
- | $result_obj = $value->scalarval(); | + | //disable SSL Keycheck |
- | //destroys "value" | + | $client->setSSLVerifyPeer(0); |
- | unset($value); | + | |
- | } | + | //----------sends the request to the server and gets the response---------- |
- | else | + | |
- | { | + | //sends the request via https and writes it into $response. timeout is set to 0 |
- | //returns the faultCode and the faultString | + | $response = $client->send($request,0,'https'); |
- | return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); | + | |
- | } | + | //generates a storable representation of $response and writes it into $result_xml |
- | //destroys "client" | + | //echo $response->serialize(); |
- | unset($client); | + | |
- | //destroys "response" | + | //checks the response. if the method "faultCode" returns zero, the response was succesfull |
- | unset($response); | + | if (0==$response->faultCode()) |
- | //----------reads the result_obj---------- | + | { |
- | //if result_obj is set then it returns the actual PHP-language value of "result_obj" | + | //returns the value sent by the server |
- | if (isset($result_obj['status'])) | + | $value = $response->value(); |
- | { | + | |
- | $value['status'] = $result_obj['status']->scalarval(); | + | //returns the actual PHP-language value of "value" |
- | } | + | $result_obj = $value->scalarval(); |
- | if (isset($result_obj['ip_address'])) | + | //destroys "value" |
- | { | + | unset($value); |
- | $value['ip_address'] = $result_obj['ip_address']->scalarval(); | + | } |
- | } | + | else |
- | if (isset($result_obj['ptr_reverse_record'])) | + | { |
- | { | + | //returns the faultCode and the faultString |
- | $value['ptr_reverse_record'] = $result_obj['ptr_reverse_record']->scalarval(); | + | return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); |
- | } | + | } |
- | return $value; | + | |
+ | //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['ip_address'])) | ||
+ | { | ||
+ | $value['ip_address'] = $result_obj['ip_address']->scalarval(); | ||
+ | } | ||
+ | |||
+ | if (isset($result_obj['ptr_reverse_record'])) | ||
+ | { | ||
+ | $value['ptr_reverse_record'] = $result_obj['ptr_reverse_record']->scalarval(); | ||
+ | } | ||
+ | return $value; | ||
} | } | ||
+ | |||
//calls the function | //calls the function | ||
$result = server_ipaddr_get_reverse($host,$port,$username,$password,$api_path,$srv_id,$ip_address); | $result = server_ipaddr_get_reverse($host,$port,$username,$password,$api_path,$srv_id,$ip_address); | ||
+ | |||
if(0==$result['faultCode']) | if(0==$result['faultCode']) | ||
{ | { | ||
- | //outputs the data | + | //outputs the data |
- | echo "Status: ".$result['status']."<br><br>"; | + | echo "Status: ".$result['status']."<br><br>"; |
- | echo "ip_address: ".$result['ip_address']."<br>"; | + | echo "ip_address: ".$result['ip_address']."<br>"; |
- | echo "ptr_reverse_record: ".$result['ptr_reverse_record']."<br>"; | + | echo "ptr_reverse_record: ".$result['ptr_reverse_record']."<br>"; |
} | } | ||
else | else | ||
{ | { | ||
- | echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; | + | echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; |
} | } | ||
?> | ?> | ||
</nowiki> | </nowiki> |
Aktuelle Version vom 07:42, 6. Sep. 2012
back to API Documentation
server.ipaddr_get_reverse
<?php //includes the class library include_once("lib/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; $ip_address="127.0.0.1"; //defines the function function server_ipaddr_get_reverse($host,$port,$username,$password,$api_path,$srv_id,$ip_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.ipaddr_get_reverse'); //adds parameters to the request $request->addParam ( //creates a value of type struct which contains an array with the username and password 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 'srv_id' => new xmlrpcval($srv_id, 'int'), //creates a value 'ip_address' => new xmlrpcval($ip_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 //echo $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['ip_address'])) { $value['ip_address'] = $result_obj['ip_address']->scalarval(); } if (isset($result_obj['ptr_reverse_record'])) { $value['ptr_reverse_record'] = $result_obj['ptr_reverse_record']->scalarval(); } return $value; } //calls the function $result = server_ipaddr_get_reverse($host,$port,$username,$password,$api_path,$srv_id,$ip_address); if(0==$result['faultCode']) { //outputs the data echo "Status: ".$result['status']."<br><br>"; echo "ip_address: ".$result['ip_address']."<br>"; echo "ptr_reverse_record: ".$result['ptr_reverse_record']."<br>"; } else { echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; } ?>