Refactor the Wrapper class to generate closures by default and avoid usage of 'eval'
[plcapi.git] / demo / client / client.php
1 <html>
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 the php_xmlrpc_encode function</h3>
9 <?php
10
11 include_once __DIR__ . "/../../src/Autoloader.php";
12 PhpXmlRpc\Autoloader::register();
13
14 if (isset($_POST["stateno"]) && $_POST["stateno"] != "") {
15     $stateNo = (integer)$_POST["stateno"];
16     $encoder = new PhpXmlRpc\Encoder();
17     $req = new PhpXmlRpc\Request('examples.getStateName',
18         array($encoder->encode($stateNo))
19     );
20     print "Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) . "\n\n</pre>Debug info of server data follows...\n\n";
21     $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
22     $client->setDebug(1);
23     $r = $client->send($req);
24     if (!$r->faultCode()) {
25         $v = $r->value();
26         print "<br/>State number <b>" . $stateNo . "</b> is <b>"
27             . htmlspecialchars($v->scalarval()) . "</b><br/>";
28         // print "<HR>I got this value back<BR><PRE>" .
29         //  htmlentities($r->serialize()). "</PRE><HR>\n";
30     } else {
31         print "An error occurred: ";
32         print "Code: " . htmlspecialchars($r->faultCode())
33             . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
34     }
35 } else {
36     $stateNo = "";
37 }
38
39 print "<form action=\"client.php\" method=\"POST\">
40 <input name=\"stateno\" value=\"" . $stateNo . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>
41 <p>Enter a state number to query its name</p>";
42
43 ?>
44 </body>
45 </html>