<?php
include("xmlrpc.inc");
// find out if we got form fields. If so - call the remote procedure
// and display the results. If not - just send back a form.
$x = $_REQUEST['x'];
$y = $_REQUEST['y'];
// hidden field that tells us whether we actually got a form submmission
$form = $_REQUEST['form'];
if ($form) {
// we will call the XML-RPC server. We need to put all the parameters in
// to an array. Each array element needs to be of type xmlrpmval,
// we just call the constructor for each one...
$params = array(
new xmlrpcval($x,"double"),
new xmlrpcval($y,"double"));
// create an xmlrpcmsg (represents the entire request)
// the method name is remoteAdd
$msg = new xmlrpcmsg('remoteAdd', $params);
// uncomment the next line to see the actual XML request
// print "<pre>" . htmlentities($msg->serialize())."</pre>\n";
// create an xmlrpc_client object - this needs to be told where the
// server is located (host, port and uri)
$client = new xmlrpc_client("/~hollingd/xml/davexmlrpc/addserv.php",
"localhost",80);
// uncomment the next line to see the server response XML document.
// $client->setDebug(1);
// send the request
$response = $client->send($msg);
// check out the response
if (! $response) {
// I/O error
echo "<H2>I/O Error - it did not work: ";
echo $client->errstring . "</H2>\n";
exit;
}
// check for a fault
if ($response->faultCode()) {
// some kind of fault! print it out
echo "<H2>Server returned fault: ";
echo $response->faultString() . "<H2>\n";
exit;
}
// we got a valid response print out the sum
// get an xmlrpcval object that holds the return value
$val = $response->value();
// we expect an int (a scalar type value)
$sum = $val->scalarval();
echo "<H2>The sum of $x and $y is $sum</H2>\n";
}
// show the form
?>
<FORM METHOD="POST">
<INPUT type="hidden" name="form" value="1">
<table border=0>
<tr>
<th>X</th>
<td><input type=text name="x"></td>
</tr>
<tr>
<th>Y</th>
<td><input type=text name="y"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=submit value="submit">
</tr>
</table>
</form>
</body>
</html>