php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14688 session_register() doesn't register
Submitted: 2001-12-24 19:00 UTC Modified: 2002-06-30 01:00 UTC
Votes:4
Avg. Score:4.2 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:0 (0.0%)
From: niklas-phpbugs at alberth dot com Assigned:
Status: No Feedback Package: Session related
PHP Version: 4.2.0RC2 OS: linux 2.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: niklas-phpbugs at alberth dot com
New email:
PHP Version: OS:

 

 [2001-12-24 19:00 UTC] niklas-phpbugs at alberth dot com
I got an array as a session var, then on one page I do

unset($basket);
$basket = array();
session_register("basket");

to empty the array but the array seems to be unaffected.

The exact same code works on 4.0.5.

4.1.0 setup:
'./configure' '--with-apxs=/usr/local/apache/bin/apxs' '--disable-debug' '--enable-track-vars' '--with-pgsql' '--with-gd=../gd-1.8.4' '--with-zlib=/usr' '--with-jpeg-dir=/usr' '--with-ttf' '--with-xslt' '--with-xslt-sablot'

--niklas 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-25 06:00 UTC] derick@php.net
What is your register_globals setting?

Derick
 [2001-12-25 07:44 UTC] niklas-phpbugs at alberth dot com
Both servers got register_globals = On.
On the 4.1.0 server i run with a php.ini that originates from the 4.0.5 release.

--niklas
 [2001-12-25 14:20 UTC] niklas-phpbugs at alberth dot com
This bug is in 4.1.1 aswell
 [2002-01-11 18:31 UTC] yohgaki@php.net
Clarification. 
Which save handler are you using files or user?
 [2002-02-02 06:38 UTC] sander@php.net
No feedback was provided for this bug, so it is being suspended.
If you are able to provide the information that was requested,
please do so and change the status of the bug back to "Open".
 [2002-03-12 13:43 UTC] colin at easydns dot com
I notice this too under 4.1.2.  unset($var) doesn't unregister $var from the session

FWIW, this is with Linux 2.4.6-pre6, and I'm using the default files for session storage.

- Colin
 [2002-04-01 15:53 UTC] sniper@php.net
AFAIK, this is fixed in CVS and PHP 4.2.0RC1.
Please test RC1 from: http://www.php.net/~derick/
and if it doesn't work, latest snapshot from http://snaps.php.net/

 [2002-04-10 05:59 UTC] valdand at soften dot ktu dot lt
Using 4.2.0.RC2 this behavior still there, you can check with these scripts:
## i2.php
<?php
session_start();
$counter = 1;
session_register("counter");
header("Location: /i.php");
?>

## i.php
<?php
session_start();
$counter = 0;
### uncomment this to see the difference
# session_unregister("counter");
session_register("counter");
unset($counter);
$counter = 4;
session_register("counter");
header("Location: /i1.php");
?>

## i1.php
<?php
session_start();
print $counter;

?>

And then open http://host/i2.php in browser window.

Expected output - 4, but I get 0.
 [2002-04-10 08:25 UTC] yohgaki@php.net
This is very strange. I have redirect and session works as it shold. 

Could you try register_globals=Off to see if it works?


 [2002-04-10 11:10 UTC] valdand at soften dot ktu dot lt
With register_globals = off I get nothing, i.e. no number, just newline, with or without session_unregister("counter"). Seems like $counter does not exist at all.
 [2002-04-11 04:18 UTC] valdand at soften dot ktu dot lt
FYI, with 4.0.5 my example scripts gives expected result - 4 with register_globals = on, and the same nothing with register_globals = off.
 [2002-04-25 12:43 UTC] valdand at soften dot ktu dot lt
4.2.0 final still has the problem. And it is a problem, not an imagination.
 [2002-05-11 00:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, 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".
 [2002-05-11 00:06 UTC] rasmus@php.net
Having a SetCookie and a Redirect in the same response causes unpredictable behaviour and will be browser-dependant.  I'd suggest not relying on this.  PHP does send both, so unless you can somehow show us an example of PHP not actually sending both the Location and the SetCookie then I don't see how this is a PHP issue.
 [2002-05-29 16:04 UTC] valdand at soften dot ktu dot lt
I see you miss the point. I have made that example of three scripts with redirects to easy things. You can equaly put links into scripts and then click them manualy with the same effect. All Set_Cookie and Redirect headers look fine. Take a look at the first message here from niklas-phpbugs@alberth.com. I can only speculate why this does not work in 4.1 or 4.2: when you register variable with session_register php it puts a referense to variable. When unset function  unsets variable, session variable still hold reference to old variable, though it does not exist anymore. When you try to reregister variable with session_register it thinks that that variable already registered, and does nothing. So whaterver new value you assign id does not reach session module, even at exit of the script. But in theory session should reference to the name of variable not variable itself, and if variable is gone in context so must session registered one. And if you use session_unregister in the same script as unset, you would get correct result. (see ### uncomment this to see the difference # session_unregister("counter");).

I don't want to insult anyone but I am amazed that such simple bug have not been fixed several monthts yet.
 [2002-05-29 16:30 UTC] rasmus@php.net
I didn't miss the point.  You should probably have stated that your example showed the problem with simple hrefs as well.  I scan things quickly and if an obvious thing such as trying to do a setcookie and a redirect in the same request is there, I comment on that and move on.

What you are seeing is a side-effect of having $HTTP_SESSION_VARS['counter'] and $_SESSION['counter'] and $counter all be references to the same data.  unset($counter) only removes one reference.  It would be inconsistent to make unset() remove all references, and the most common usage is simply $counter = new_value which works correctly.  Doing a second session_register() on the same variable doesn't currently do anything since it is already registered unless of course you have called session_unregister on it.  So in summary, I think this is a fringe case that needs documenting and not necessarily fixing unless someone can come up with a clean and consistent fix.
 [2002-05-30 11:05 UTC] valdand at soften dot ktu dot lt
So please at least document that such fringe case which works in 4.0.5, 4.0.6 does not work in 4.1, 4.2, and scripts need code changes in order to run as expected on 4.1, 4.2.
 [2002-06-30 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, 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".
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Dec 05 09:03:49 2022 UTC