<?
function sessao_open($aSavaPath, $aSessionName)
{
       global $aTime;

       sessao_gc( $aTime );
       return true;
}

function sessao_close()
{
       return true;
}

function sessao_read( $aKey )
{
		global $db;
		
		$query = "SELECT dataValue FROM tSession WHERE sessionId='$aKey'";
		$result = $db->QueryToRow($query, MYSQL_ASSOC);
		if( $result )
		{
		     return $result['dataValue'];
		}
		else
		{
		     $query = "INSERT INTO tSession (sessionId, lastUpdated, dataValue) VALUES ('$aKey', NOW(), '')";
		     $db->Query($query);
		     return "";
		}
}

function sessao_write( $aKey, $aVal )
{
		global $db;
		
		$aVal = addslashes( $aVal );
		$query = "UPDATE tSession SET dataValue = '$aVal', lastUpdated = NOW() WHERE sessionId = '$aKey'";
		$db->Query($query);
		return true;
}

function sessao_destroy( $aKey )
{
       return true;
}

function sessao_gc( $aMaxLifeTime )
{
		global $db;
		
		$query = "DELETE FROM tSession WHERE UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(lastUpdated) > 72000";//$aMaxLifeTime";
		$db->Query($query);
		return true;
}

session_set_save_handler("sessao_open", "sessao_close", "sessao_read", "sessao_write", "sessao_destroy", "sessao_gc"); 
session_name("BC_SID");
?>