topical media & game development
server-webapi-code-12-restAPIFramework.php / php
<?php
require("../common_db.php");
//Plug in authentication function here, remember to escape strings if the
// destination function doesn't do it for you.
if (!checkUser(mysql_escape_string(_GET['password'])))
{
echo <<< endquote
<response>
<error no="1">Invalid Username or Password</error>
</response>
endquote;
exit;
}
//Plug in throttling function here if desired
if (userThrottled(API = array();
/* Example:
optionalValues = array("year", "publisher");
expectedValues, expectedValues = array("keyword");
API[] = array("search", "searchCall", optionalValues);
describeAPI(
//Framework iterates through array looking to match the requested method
// with a service the framework provides
error = array();
validRequestFormat = false;
foreach(item)
{
if (_GET['method'])
{
validRequestFormat = checkValues(item[2], error);
break;
}
}
//Framework was unable to match method, return an error
if (validRequestFormat == false)
{
echo "<response>\n" . implode("\n",item[1], request, optional, &required[] = "method";
required[] = "password";
// Ensure all elements passed are either requied or optional
requestTemp = array_diff(array_keys(optional);
requestTemp, requestTemp) > 0)
{
print_r(requestTemp as unknownValue)
{
// *SECURITY ISSUE*
// Failing to escape the user data present in error[] = "<error no=\"101\">Unknown Element: error[] = "<error no=\"101\">Unknown Element: " . htmlentities(requiredTemp = array();
required, array_keys(requiredTemp) > 0)
{
foreach (missingElement)
{
missingElement</error>";
}
}
if (count(API)
{
foreach(service)
{
echo "<b>Method Name:</b> {service[2]) . "<br>";
echo "<b>Optional Parameters:</b> " . implode(",", username, request)
{
echo "SearchCall has been called, I will handle the request as best I can!";
}
function userThrottled(
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.