API Documentation RunningExamples domain.redirect create record PHP

Aus EUserv Wiki

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

back to API Documentation

domain.redirect_create_record

 
<?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="/";
$domain_id=1337;
$redirect_record_type="headerredirect";
$redirect_record_subdomain="";
$redirect_record_location="http://euserv.de/";
$redirect_record_status_code =301;
$redirect_record_title="";
$redirect_record_description="";
$redirect_record_author="";
$redirect_record_keywords="";
$redirect_record_robots="";
$redirect_record_favicon="";


//defines the function
function domain_redirect_create_record($host,$port,$username,$password,$api_path,$domain_id=51063,$redirect_record_type,$redirect_record_subdomain,$redirect_record_location,$redirect_record_status_code,$redirect_record_title,$redirect_record_description,$redirect_record_author,$redirect_record_keywords,$redirect_record_robots,$redirect_record_favicon)
{

  //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('domain.redirect_create_record');
  
  //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
        'domain_id' => new xmlrpcval($domain_id),
        
        //creates a value
        'redirect_record_type' => new xmlrpcval($redirect_record_type),
      
        //creates a value
        'redirect_record_subdomain' => new xmlrpcval($redirect_record_subdomain),
      
        //creates a value
        'redirect_record_location' => new xmlrpcval($redirect_record_location),
      
        //creates a value
        'redirect_record_status_code' => new xmlrpcval($redirect_record_status_code),
      
        //creates a value
        'redirect_record_title' => new xmlrpcval($redirect_record_title),
      
        //creates a value
        'redirect_record_description' => new xmlrpcval($redirect_record_description),
      
        //creates a value
        'redirect_record_title' => new xmlrpcval($redirect_record_title),
      
        //creates a value
        'redirect_record_description' => new xmlrpcval($redirect_record_description),
      
        //creates a value
        'redirect_record_author' => new xmlrpcval($redirect_record_author),
        
        //creates a value
        'redirect_record_keywords' => new xmlrpcval($redirect_record_keywords),
      
        //creates a value
        'redirect_record_robots' => new xmlrpcval($redirect_record_robots),
      
        //creates a value 
        'redirect_record_favicon' => new xmlrpcval($redirect_record_favicon),
      )
      ,'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['redirect_record_id']))
  {
    $value['redirect_record_id'] = $result_obj['redirect_record_id']->scalarval();
  }  
    
  return $value;    
}

//calls the function
$result = domain_redirect_create_record($host,$port,$username,$password,$api_path,$domain_id=51063,$redirect_record_type,$redirect_record_subdomain,$redirect_record_location,$redirect_record_status_code,$redirect_record_title,$redirect_record_description,$redirect_record_author,$redirect_record_keywords,$redirect_record_robots,$redirect_record_favicon);

if(0==$result['faultCode'])
{
  echo "Status: ".$result['status']."<br><br>".$result['redirect_record_id'];
}
else
{
  echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString'];
}
?>