On Tue, Apr 24, 2012 at 12:58 AM, bug zhu <bugwhen@xxxxxxxxx> wrote: > there are tow php files a.php and b.php, > > content of a.php as follows: > <?php > session_start(); > if (!isset($_GET['flag'])) > { > header('Location: b.php'); > } > else > { > var_dump($_SESSION); > } > > content of b.php as follows: > <?php > session_start(); > session_commit(); > $_SESSION['test'] = 'test'; > session_commit(); > header('Location: a.php?flag=1'); > > when i visit a.php, the dumped $_SESSION array is empty > but if i commented the first session_commit() in b.php and then visit > a.php, i cound see the $_SESSION array,which is not empty > i wish i have descibed clear about my problem and someone could give me a > feedback~ Hi, So, you: 1) Visit page a.php (I'm assuming without the flag) 2) Are forwarded to page b.php, which you're expecting to store a session variable 'test'. 3) Then forwarded back to page a.php. You're likely expecting that you're return visit to page a.php should reveal the 'test' variable. The issue is that you're calling session_commit(), which is actually an alias for session_write_close(). This function actually stops the current session. So, when you hit the line $_SESSION['test'] = 'test', your session has already terminated. Try removing the session_commit() calls (or at least permanently remove the first call.) You only want to call session_commit() when you're done accessing/updating $_SESSION variables. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php