每当我重新加载页面时,仍会设置取消设置PHP会话变量[重复]

This question already has an answer here:

My problem is when i unset a session variable then reload login.php, the session variable is still set.

Here is what i'm trying to do:

I'm trying to send an error message through a session variable that is set in reset.php

<?php
session_start();
$_SESSION['reset-msg'] = "This link has already been used";
header("Location: {$url}login.php");
exit();
?>

Login.php should check if this session is set then displays the error message and unset the session variable.

<?php
session_start();

if(isset($_SESSION['reset-msg']) && !empty($_SESSION['reset-msg'])){

   print_r($_SESSION);//prints "Array ( [reset-msg] => This link has already been used )"
   $warn_msg = $_SESSION['reset-msg'];
   $_SESSION['reset-msg'] = "";
   unset($_SESSION['reset-msg']);

}else{
   $warn_msg = "";
}
print_r($_SESSION);//prints "Array ( )"
exit;
?>

However, i still get the same message every time i reload login.php.

The only error showing in the log file

PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /login.php:1) in /login.php on line 2

</div>

use session_destroy or define session index blank

Use the following. It will destroy the session

session_start();
session_unset();
session_destroy();
header('location:your-desired-location.php');