php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #30151 session_encode() encodes old data?
Submitted: 2004-09-19 11:56 UTC Modified: 2005-04-05 16:15 UTC
From: bugs dot php dot net at b-a-l-u dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Linux (Debian Woody)
Private report: No CVE-ID: None
 [2004-09-19 11:56 UTC] bugs dot php dot net at b-a-l-u dot de
Description:
------------
In PHP 4.1.2 (Debian Woody) seems to be a problem with session_encode(); This problem was probably fixed already in later versions, as I receive correct results in PHP 5.0.1 (local wampp installation of the apachefriends package).

However - a small note in the PHP documentation regarding this problem would have saved me a lot of debugging time. Especially if I was told at which version this was fixed, so I might raise the minimum PHP version requirements of my scripts or find a workaround somehow... Because of this I am filing it as a documentation problem.

The problem is that session_encode() seems to encode old session information or perhaps does not use $_SESSION as a source for the data to be encoded. See the examples below for the effect.

On both PHP versions register_globals is enabled.

I am not sure if this is related to "If you enable register_globals, session_unregister() should be used since session variables are registered as global variables when session data is deserialized." (http://php.net/manual/en/ref.session.php)



Reproduce code:
---------------
<?php
session_start();
print('<a href="A.php">load again</a><br />');
print(session_id().'<br />');

$_SESSION['count']++;

var_dump($_SESSION); echo '<br />';
print(session_encode().'<br />');

/* delete this line to enable "resetting" of the array
print('Resetting session array<br />');
$_SESSION = array();
var_dump($_SESSION); echo '<br />';
print(session_encode().'<br />');
/* */
?>

Expected result:
----------------
In PHP Version 5.0.1 the following happens (which looks ok) (added some notes starting with "//"):

e23b68a2ae188a2ad69540f293435af1
array(1) { ["count"]=> int(1) }
count|i:1; // session_encode() correctly starts with session data

e23b68a2ae188a2ad69540f293435af1
array(1) { ["count"]=> &int(2) }
count|i:2; 

Now I enable the "reset" of the session array: 

e23b68a2ae188a2ad69540f293435af1
array(1) { ["count"]=> &int(3) }
count|i:3;
Resetting session array
array(0) { } 
// the session_encode call correctly returns ""

e23b68a2ae188a2ad69540f293435af1
array(1) { ["count"]=> int(1) }
count|i:1;
Resetting session array
array(0) { } 

Actual result:
--------------
In PHP 4.1.2 I get the following output: (added some notes starting with "//")

97debb21091253568094c82ebdfd9ca0
array(1) { ["count"]=> int(1) } 
// no session_encode data?

97debb21091253568094c82ebdfd9ca0
array(1) { ["count"]=> &int(2) }
count|i:2;

Now I enable the "reset" of the session array: 


97debb21091253568094c82ebdfd9ca0
array(1) { ["count"]=> &int(3) }
count|i:3;
Resetting session array
array(0) { } // the $_SESSION array is empty, but 
count|i:3;   // session_encode still maintains the old content?

97debb21091253568094c82ebdfd9ca0
array(1) { ["count"]=> &int(4) }
count|i:4;
Resetting session array
array(0) { } 
count|i:4;   

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-19 12:12 UTC] bugs dot php dot net at b-a-l-u dot de
It seems to work as expected if I do the following to remove count from the session.

$_SESSION = array();
session_unregister('count');

However - the PHP documentation tells me that "If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister()." - so doing so is probably wrong.
 [2005-04-05 16:15 UTC] dmytton@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Aug 06 05:00:02 2025 UTC