ID:               32564
 Comment by:       cristic at interaktonline dot com
 Reported By:      echenavaz at mengine dot fr
 Status:           No Feedback
 Bug Type:         Session related
 Operating System: debian 2.6.9
 PHP Version:      5.0.4
 New Comment:

This problem is duplicating on WinXP Pro (SP2) Apache 1.3.33 PHP 5.0.4

register_globals = Off
register_long_arrays= Off

If you have 3 php pages with the following code:
1.php:
<?php 
@session_start();
$_SESSION['var1'] = 'val1';
$_SESSION['var2'] = 'val2';
$_SESSION['var3'] = 'val3';
var_dump($_SESSION);
?>
click <a href="2.php">here</a> for page 2

2.php:
<?php 
@session_start();
foreach($_SESSION as $k=>$v){
   unset($_SESSION[$k]);
}
var_dump($_SESSION);
?>
click <a href="3.php">here</a> for page 3

3.php:
<?php 
@session_start();
var_dump($_SESSION);
?>
Finish!

The results in the browser will be:

1.php:


array(3) { ["var1"]=> string(4) "val1" ["var2"]=> string(4) "val2"
["var3"]=> string(4) "val3" } 
click here for page 2 

2.php:

array(0) { } 
click here for page 3 

3.php:

array(3) { ["var1"]=> string(4) "val1" ["var2"]=> string(4) "val2"
["var3"]=> string(4) "val3" } Finish! 

Now, if you turn On the register_long_arrays this will work as expected
having on page 3 an empty session.

Also if you execute outside a foreach loop the unset is working as
well.

Contact me if you need more details.


Previous Comments:
------------------------------------------------------------------------

[2005-04-27 17:53:09] bugs dot php dot net at enca dot cz

In this testcase the "write" function is not called. If you comment
line with "unset", the write function is called properly. If you delete
whole foreach cycle and use 
"unset($_SESSION['A']);" instead, the "write" function si also called -
as expected. This bug appear only when you call "unset" inside foreach
cycle.

My environment: 
MS Windows Server 2003 SE (Windows NT 5.2 build 3790)
Apache/2.0.53 (Win32) PHP/5.0.4
I can provide more information if you ask for them.

<?php
function foo(){
  return(true);
}
function read($id){
  return 'A|s:1:"a";B|s:1:"b";';
}
function write($id, $sess_data){
  print "I'm writing this data: \n";
  print_r($sess_data);
  return true;
}

header('Content-Type: text/plain');
session_set_save_handler("foo", "foo", "read", "write", "foo", "foo");
session_start();
print_r($_SESSION);
foreach($_SESSION as $lsKey => $lsVal){
  if($lsKey != 'A'){
    unset($_SESSION[$lsKey]);  //<<<<<<<< if you comment this line, the
write function is called properly
  }
}
print_r($_SESSION);
print("finished\n");

?>

------------------------------------------------------------------------

[2005-04-12 01:00:05] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

------------------------------------------------------------------------

[2005-04-05 17:07:33] derek dot ethier at humber dot ca

More information:
This "problem" does not exist with 5.0.2 on Windows 2003 (IIS6).

duh at dowebwedo dot com's method does work within the execution of
that one script, but the unset variables are not persistent.  The
$_SESSION variables are restored on each subsequent page load even
after they have been unset which leads to problems with session
fixation and the inability to clean-up session values that are no
longer needed.

------------------------------------------------------------------------

[2005-04-04 18:56:56] derek dot ethier at humber dot ca

I can confirm this problem with Windows Server 2003, PHP 5.0.4.  Sample
code:

<?php
function unsetSessionVariables($session_name) {
    foreach ($_SESSION as $session_key => $session_variable) {
        if (strstr($session_key, $session_name)) {
            // Neither of these work as intended.
            unset($GLOBALS[_SESSION][$session_key]);
            unset($_SESSION[$session_key]);
        }
    }
}

unsetSessionVariables("session_name");
?>

I have verified that the same problem exists in the latest 5.1 snap
(php5-win32-200504041430) on the same platform.

------------------------------------------------------------------------

[2005-04-04 12:43:10] duh at dowebwedo dot com

I did not experience any problems with Apache/1.3.29 (Unix) PHP/5.0.4
on Debian stable.
Code:
<?php
  $_SESSION['one'] = 1;
  $_SESSION['two'] = 2;
  $_SESSION['three'] = 3;

  print_r($_SESSION);

  foreach ($_SESSION as $key_session => $session)
        unset($_SESSION[$key_session]);

  print_r($_SESSION);
?>

Result is as expected:
Array ( [DF_debug] => 1 [one] => 1 [two] => 2 [three] => 3 ) Array ( )

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/32564

-- 
Edit this bug report at http://bugs.php.net/?id=32564&edit=1

Reply via email to