php says session not set while it has been set

i have a php script to login, i set a session to store username value in it, when login is successful then it redirects me to another page that is the main page of the site. in this page every time i try to run my code, it returns session is not set. someone help me?
here is my code – login page :

<?php
session_start();
unset($_SESSION['username']);
//error_reporting(0);
$username = filter_var($_POST['username']);
$password = filter_var($_POST['password']);

$login = new Login();
if(isset($_POST['submit'])){
    
    if($login->login($username, $password)){
        $_SESSION['username'] = $_POST['username'];
        header("Location: kartablContent/index.php");
        echo "
             <div class='alert alert-success alert-dismissible fade show'>
    <button type='button' class='btn-close' data-bs-dismiss='alert'></button>
    <strong>عملیات موفق</strong> در حال ورود به حساب کاربری ...
  </div>
        ";

        
    }else{
        echo "
                   <div class='alert alert-danger alert-dismissible fade show'>
    <button type='button' class='btn-close' data-bs-dismiss='alert'></button>
    <strong>عملیات ناموفق</strong> نام کاربری یا رمز عبور اشتباه است
  </div>
        ";
    }
}


?>

here is my main page code:

<?php
session_start();
if (isset($_SESSION['username'])) {
    $username = $_SESSION['username'];
    echo "Welcome, $username!";
} else {
    echo "Session variable not set.";
}
?>

so every time i get session variable not set and it drives me crazzzyyyyyy…..

i tried every way but did not get a suitable result