<?php
function isDebug(){
return isset($_POST['debug']) || isset($_GET['debug']);
}
function footprint($message = ''){
if(empty($message)) return;
if(isDebug()) echo $message . "\n";
}
[COLOR=#EF2929]ob_start();[/color]
require_once "dbconnect.php";
footprint("connected to db");
require_once $_SERVER['DOCUMENT_ROOT'].'/user_header.php';
footprint("done sessions");
[COLOR=#EF2929]if(!isDebug()) ob_end_clean();[/color]
if(!function_exists('json_encode')):
footprint('json_encode function does not exist');
die;
endif;
if (! @mysql_select_db($database) ):
echo json_encode(array( 'result'=>'error',
'errorMessage'=>'Unable to locate the database at this time.'));
die;
else:
footprint('selected database');
endif;
/* change back to POST when the scripts are working */
/* useful to allow GET requests while debugging */
if(!isset($_REQUEST['id'])):
echo json_encode(array( 'result'=>'error',
'errorMessage'=>'No ID provided.'));
die;
endif;
$id = mysql_real_escape_string($_REQUEST['id']); //always escape and enquote all user input to avoid sql injection
$allowedusers = array("bill", "john");
if (in_array($user, $allowedusers)):
footprint('user is allowed');
$result = @mysql_query("SELECT secretvoodoo from voodoo_list WHERE id = '$id'");
if($result):
footprint('secretvoodoo query done');
$row = @mysql_fetch_assoc($result);
if(!$row):
echo json_encode(array( 'result'=>'error',
'errorMessage'=>"Nothing found for that ID"
));
die;
else:
echo json_encode(array( 'result'=>'ok',
'data'=>$row['secretvoodoo']
));
die;
endif;
else:
echo json_encode(array( 'result'=>'error',
'errorMessage'=>mysql_error()
));
die;
endif;
else:
echo json_encode(array( 'result'=>'error',
'errorMessage'=>"unauthorized"
));
die;
endif;
?>