0
page1.php

$_SESSION['sVar'] = 'XYZ';
header('Location:page1.php');

page1.php
echo $_SESSION['sVar']; // Works well

page1.php
echo  $_SESSION['sVar']; // donot get displayed after adding following line
unset($_SESSION['sVar']);

我的问题是:当我是回显会话变量时,它运行良好,但是当我在回显后销毁该变量时,它没有得到回显。

4

1 回答 1

0

这对我来说很好

session1.php:

<?php
    session_start();
    $_SESSION['sVar'] = 'somecrap';
    header("Location: session2.php");
    exit;

session2.php:

<?php
    session_start();
    echo $_SESSION['sVar'];
    unset($_SESSION['sVar']);

显然,如果我刷新 session2.php,我会收到未定义的索引警告

您是否在两个页面中都开始会话?

于 2012-12-13T11:58:12.137 回答