php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39193 unset($_SESSION[$key]) not saving session after reload
Submitted: 2006-10-19 04:01 UTC Modified: 2006-11-07 17:34 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: gearb0x at eml dot cc Assigned: iliaa (profile)
Status: Not a bug Package: Session related
PHP Version: 5.1.6 OS: Linux FC4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gearb0x at eml dot cc
New email:
PHP Version: OS:

 

 [2006-10-19 04:01 UTC] gearb0x at eml dot cc
Description:
------------
For some reason unseting session variables is stopping php from saving any session variables. The code below should clear the session but it isnt, this code worked fine on 5.1.2 on a freeBSD box. Also ive noticed that if i make any changes to the session variables (ie: adding new ones) they dont get saved in the session either

Reproduce code:
---------------
<?php

session_start();

foreach($_SESSION as $key=>$value)
{
	unset($_SESSION[$key]);
}

?>

Expected result:
----------------
This should clear the session. Also, any other changes made to the session arent saved either (ie: creating more session variables


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-19 04:19 UTC] gearb0x at eml dot cc
replacing unset($_SESSION[$key]) with session_unregister($key) has the desired effect -- which your not suposed to use according to all docs.
 [2006-10-19 07:47 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

>This should clear the session. 
But it does ... instead?
 [2006-10-19 15:40 UTC] gearb0x at eml dot cc
It doesnt clear it, all variables stay intact as they were when the session started. It clears it in the current execution of the script, but the next time the page loads all the variables are back as they were before they were unset call

If i make any changes to session variables AFTER ive tried to unset one they are not saved in the session on the next page load

Its as if the session doesnt save, even forcing the save with session_write_close does not work
 [2006-10-21 03:43 UTC] john dot cecere at sun dot com
I ran into this today with PHP 5.1.6. I spent most of the afternoon trying to figure out why my vars were coming back after a header() call. 

One might suggest that this isn't a bug and that this behavior is described in the docs (the session_unregister page for example). I would disagree with this. This behavior is very quirky and completely counter-intuitive. It would be much better for unset to behave in a way that you would expect, i.e. to unset a variable (or element of a variable) so that it stays unset, regardless of whether that variable happens to be $_SESSION or not.

John
 [2006-11-07 17:34 UTC] iliaa@php.net
I've tried to replicate the described problem however the 
code appears to work properly.
I've made 3 scripts:

A:
        session_start();
        $_SESSION['A'] = 1;
        $_SESSION['B'] = 'afdsf';

B:
session_start();
foreach($_SESSION as $key=>$value)
{
        unset($_SESSION[$key]);
}

C:
session_start();
var_dump($_SESSION, session_id());


The code shows that the unset loop is in fact successful in 
clearing out & saving session data.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 20:01:31 2024 UTC