<?php

// Session lifetime settings

ini_set('session.gc_maxlifetime', 7200); // 2 hours

ini_set('session.cookie_lifetime', 7200); // 2 hours



session_name("student_portal");

session_start();



// Detect tab_id from GET or SESSION

if (isset($_GET['tab_id']) && $_GET['tab_id'] !== '') {

    $tabSessionID = $_GET['tab_id'];

    $tabSessionID1 = $tabSessionID;  // for backward compatibility

    $_SESSION['current_tab_id'] = $tabSessionID;

} elseif (isset($_SESSION['current_tab_id'])) {

    $tabSessionID = $_SESSION['current_tab_id'];

    $tabSessionID1 = $tabSessionID;

} else {

    header("Location: index.php?error=2");

    exit();

}



// OPTIONAL: Check if this tab exists in our tabs array

if (!isset($_SESSION['tabs'][$tabSessionID])) {

    header("Location: index.php?error=3"); // Invalid tab

    exit();

}



// Update last active time to keep session alive

$_SESSION['tabs'][$tabSessionID]['last_active'] = time();



// Make tab session data available for pages that include this

$studentSession = $_SESSION['tabs'][$tabSessionID];



// Sync tab session data to global $_SESSION keys for compatibility

$_SESSION['student_id']  = $studentSession['student_id'];

$_SESSION['class']       = $studentSession['class'];

$_SESSION['scholarship'] = $studentSession['scholarship'];

$_SESSION['spcase']      = $studentSession['spcase'];

$_SESSION['stream']      = $studentSession['stream'];


