php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14809 global session vars are being assigned by value, not reference
Submitted: 2002-01-02 16:51 UTC Modified: 2002-01-07 09:10 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: winterchild at pobox dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.1.1 OS: linux 2.4.7-10
Private report: No CVE-ID: None
 [2002-01-02 16:51 UTC] winterchild at pobox dot com
hi
This seems to be a problem with the way session variables register in 4.1.1
I have defined a session variable called $session thus:
session_start();
                session_register("session");
                global $session;
                $session['profileName'] = "name";

This seems to work fine.  On the next page I do:

session_start();
global $session;
echo "profileName=".$session['profileName']; (displays name)
$session['profileName']="new name";

however, this doesn't seem to actually change the session variable, since on the next page if i echo $session['profileName'] it still shows 'name' instead of 'new name'

I can modify the session var value using $_SESSION[session][profileName]="new name"; and then it works fine on the next page.

The latter format worked with 4.0.5, i just installed 4.1.1 and now apparently I have to modify all my scripts..

Here is my config:
'./configure' '--with-mysql' '--with-apxs=/usr/local/apache/bin/apxs' '--enable-track-vars=yes'

register_globals is on.
apache version is 1.3.20

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-07 02:38 UTC] yohgaki@php.net
I guess you are using session register within a function, right?
If so, please ask support question to php-general.
If not, reopen this bug report with short/complete script.
 [2002-01-07 09:10 UTC] winterchild at pobox dot com
No, I'm not using it within a function.  Here is a small script that will reproduce the problem:

page1.php:

<?
// page1.php
session_start();
session_register("session");
global $session;
$session['profileName'] = "name";
echo "session var value is ".$session['profileName']; 
// will be "name"
echo "<br>click <a href= 'page2.php' >here</a> to continue:";
?>
----------
page2.php:

<?
page2.php
session_start();
global $session;
echo "session var initial value is ".$session['profileName'];
// will be "name"
$session['profileName']="new_name";
echo "session var new value is ".$session['profileName']."<br>";
// will be new_name
echo "but actual session var value is ".$_SESSION[session][profileName]."<br>";
// note the difference in output!
// $session['profileName'] is "new_name"
// but $_SESSION[session][profileName] is still "name"
echo "click <a href='page3.php'>here</a> to continue";
--------

page3.php:

<?
//page3.php
session_start();
global $session;

echo "session var is now".$session['profileName'];
// will be name instead of new_name.


-----------
cheers!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 12:01:32 2024 UTC