About Sitellite       Screenshots       Downloads       Forge      Documentation       Community       Support

You are here: Home / Client-Side RPC in Sitellite

Client-Side RPC in Sitellite

The Server-Side Handler

The 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...
Page 2: The End User Interface
Page 3: The Server-Side Handler
Page 4: Further Thoughts

Members

Note: You can use your SitelliteForge.com account here and vice versa.

Username

Password

Forgot your password?

Not a member? Click here to register

Sitellite 5 Beta


Copyright © 2008, SIMIAN systems Inc.
All rights reserved. Privacy policy
Some of the icons on this site were created by the Gnome Project.