我的方式出了什么问题;我正在建立一个PHP会话


What is wrong with the way I'm establishing a PHP session?

我正在使用以下代码。会议正在同一页上进行;在下一页中,它没有显示会话变量值。请告诉我我做错了什么?

<?php 
    session_start();
    $_SESSION['emailaddress']=$emailAddress;
    header("Location: $success "); /* Redirect browser */
    exit;
?>

在访问的会话值之前,也要在重定向到的页面中使用session_start()$success

因此,"success.php"页面看起来像:

<?
session_start();
print_r($_SESSION); 
?>
<?php
if(some_condition is true)
{
session_regenerate_id();
session_start();
$_SESSION['emailaddress']=$emailAddress;
header("location: member-index.php");
exit();
}

在安全页面上:

<?php
//Start session
session_start();
//Check whether the session variable is present or not
       if(!$_SESSION['emailAddress']) 
        {
        header("location: access-denied.php");
        exit();
    }
?>
<p>This is secured page with session: <b><?php echo $_SESSION['emailAddress']; ?></b>