merge upstream phpxmlrpc
[plcapi.git] / php / phpxmlrpc / demo / client / getstatename.php
1 <?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
2 <head><title>xmlrpc - Getstatename demo</title></head>
3 <body>
4 <h1>Getstatename demo</h1>
5
6 <h2>Send a U.S. state number to the server and get back the state name</h2>
7
8 <h3>The code demonstrates usage of automatic encoding/decoding of php variables into xmlrpc values</h3>
9
10 <p>You can see the source to this page here: <a href="getstatename.php?showSource=1">getstatename.php</a></p>
11 <?php
12
13 if (isset($_POST["stateno"]) && $_POST["stateno"] != "") {
14     $stateNo = (integer)$_POST["stateno"];
15     $encoder = new PhpXmlRpc\Encoder();
16     $req = new PhpXmlRpc\Request('examples.getStateName',
17         array($encoder->encode($stateNo))
18     );
19     print "Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) . "\n\n</pre>Debug info of server data follows...\n\n";
20     $client = new PhpXmlRpc\Client(XMLRPCSERVER);
21     $client->setDebug(1);
22     $r = $client->send($req);
23     if (!$r->faultCode()) {
24         $v = $r->value();
25         print "<br/>State number <b>" . $stateNo . "</b> is <b>"
26             . htmlspecialchars($encoder->decode($v)) . "</b><br/><br/>";
27     } else {
28         print "An error occurred: ";
29         print "Code: " . htmlspecialchars($r->faultCode())
30             . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
31     }
32 } else {
33     $stateNo = "";
34 }
35
36 print "<form action=\"getstatename.php\" method=\"POST\">
37 <input name=\"stateno\" value=\"" . $stateNo . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>
38 <p>Enter a state number to query its name</p>";
39
40 ?>
41 </body>
42 </html><?php require_once __DIR__ . "/_append.php"; ?>