$tenantID = $_SESSION['tenantID']; Context::$tenantid = $tenantID; if (!isset($_SESSION['userID'])) { // set ID to 0 to indicate unauthenticated user $_SESSION['userID'] = 0; $userID = 0; } else { $userID = $_SESSION['userID']; } Log::debug('instantiating new user for userID=' . $userID, 1); $user = new User($userID, $tenantID); Context::$currentUser = $user; if ($newsession) { Log::startSession(session_id(), $tenantID, $userID); } if ($userID > 0 && !$user->canAccessTenant($tenantID)) { Log::debug('Unauthorized user attempted to access tenant page. (user='******', tenant=' . $tenantID . ')', 9); header('HTTP/1.0 403 Forbidden'); echo '<p>You are not allowed to access this resource.</p>'; exit; } elseif ($userID == 0) { // TO DO: check whether tenant allows anonymous access // for now, assume that they all do $allowAnon = Utility::getTenantProperty($applicationID, $tenantID, $userID, 'allowAnonAccess'); if (!$allowAnon && strtolower(basename($_SERVER['PHP_SELF'])) != 'login.php') { //echo strtolower(basename($_SERVER['PHP_SELF'])); Log::debug('Unauthenticated user attempted to access tenant page. Redirecting to login. (tenant=' . $tenantID . ')', 9); header('Location: Login.php?context=loginRequired'); die; } }