PHP Echo会话然后取消设置

I am trying to echo a session and then unset it. I have this code:

    <?php
    if(isset($_SESSION['error']))
    {
    ?>
          <div class="alert alert-danger" style="border-radius:0;margin-bottom:0;">
              <i class="glyphicon glyphicon-warning-sign"></i> &nbsp; <?php echo $_SESSION['error'];unset($_SESSION['error']);?>
          </div>
    <?php
    }
    ?>

I think the session is destroyed before it is echoed.

I fixed this now :)

$_SESSION['error'] = 'Error message!';
$user->redirect('index.php');
exit(); --> this exit fixed it

and then

if(isset($_SESSION['error']))
{
echo $_SESSION['error'];unset($_SESSION['error']);
}

Call session_start(); on the beggining of your php code in order to work with sessions.

<?php
    session_start();
    if(isset($_SESSION['error']))
    //...

If the session is started and the HTML part is not showing, is because there is no such index 'error' in your sessions.

<?php
if(isset($_SESSION['error']))
{
?>
      <div class="alert alert-danger" style="border-radius:0;margin-bottom:0;">
          <i class="glyphicon glyphicon-warning-sign"></i> &nbsp; <?php echo $_SESSION['error']; ?>
      </div>
<?php
}
unset($_SESSION['error']);
?>

Try that. Untested on my side though.