<?php
// include database and object files
include_once '../config/init.php';	// contains $db
include_once '../config/error.php';
include_once '../objects/db_session.php';

// prepare user object
$gameSession = new GameSession($db);

// read mandatory $_POST properties : ensure sessionId is passed in $_POST parameters
if (isset($_POST['sessionId']))
	$gameSession->id = $_POST['sessionId'];
else trigger_error( missing_parameter_error("sessionId") );

$cached = cache_get($gameSession->id, "session");
if ($cached !== null)
{
	print_r($cached);
}
else if ($gameSession->load())
{
	$session_arr = $gameSession->getResultArray(true, "Session_Found");
	$json = json_encode($session_arr);
	cache_put($gameSession->id, "session", $json);
	print_r($json);	// OK
}
else trigger_error("Error_Occured");
?>