|
You are here: Home / Client-Side RPC in Sitellite |
Client-Side RPC in SitelliteThe Server-Side HandlerThe last step to our calculator app is to create the server-side RPC handler. This is where the actual calculations will take place (although in the real world, there's no reason why a calculator couldn't -- and shouldn't -- be written exclusively in JavaScript). inc/app/calculator/boxes/rpc/index.php
<?php
// import the RPC package
loader_import ('saf.Misc.RPC');
// valid operations
$ops = array (
'add' => ' + ',
'sub' => ' - ',
'mult' => ' * ',
'div' => ' / ',
'mod' => ' % ',
);
// verify that the values won't get us hacked
if (
! isset ($ops[$parameters['func']]) ||
! is_numeric ($parameters['v1']) ||
! is_numeric ($parameters['v2'])
) {
echo rpc_response (false);
exit;
}
// we'll eval the expression in the form:
// $ans = $v1 $func $v2;
eval (CLOSE_TAG . OPEN_TAG . ' $ans = ' . $parameters['v1'] . $ops[$parameters['func']] . $parameters['v2'] . '; ' . CLOSE_TAG);
// respond with $ans and exit
echo rpc_response ($ans);
exit;
?>
As you can see, client-side RPC programming in Sitellite is an easy way to add some flair to your web applications, without introducing a lot of unnecessary complexity. Page 1: Since the launch of Google's Gma... |
|
Copyright © 2008, SIMIAN systems Inc. All rights reserved. Privacy policy Some of the icons on this site were created by the Gnome Project. |