<?php
//get all sessions id
$sessions = array();

$path = realpath(session_save_path());
$files = array_diff(scandir($path), array('.', '..'));

foreach ($files as $file)
{
    //$sessions[$file] = unserialize(file_get_contents($path . '/' . $file));
	$s = explode("_", $file);
	$sessions[$s[1]] = true; 
}
//get sessions from ecmreservations
include_once("/var/www/crm/config.php");
$db = new mysqli($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],
$sugar_config['dbconfig']['db_password'], $sugar_config['dbconfig']['db_name']);


$res = $db->query("SELECT distinct session_id as sid FROM ecmreservations");


while ($row=$res->fetch_assoc()) {
	if (!isset($sessions[$row['sid']]))
		$db->query("DELETE FROM ecmreservations WHERE session_id='".$row['sid']."'");
}
return true;
?>