ID:               32564
 Comment by:       bugs dot php dot net at enca dot cz
 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:

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");

?>


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

[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 ( )

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

[2005-04-04 10:23:51] [EMAIL PROTECTED]

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 possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.



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

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