So I have been trying to work with session but it seems my code is not working. My session_start() function when creating session is inside of an if statement after validating login from server, not at the start of PHP. The following are my codes:
//Creating sessions
        session_start();
        $_SESSION['last_active'] = time();
        $_SESSION['username'] = 
        $logged_user;
        //redirecting from login page to any page.
        //refresh sets the redirect time.
        header("Refresh: 3; URL=redirect_after_login.php");
The following is the code after redirect:
session_start();
if(isset($_SESSION['last_active']) && (time() - $_SESSION['last_active'])>10)
{
/*
##This if statement checks if the last activity session is set or not
##Then checks if the time is more than 10 minutes.
*/
session_destroy();
header('Location = login.php');}
