php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14785 cannot save data with session_register() in functions
Submitted: 2002-01-01 01:18 UTC Modified: 2002-01-10 17:39 UTC
From: y0rt at hotmail dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.1.0 OS: Debian Linux
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: y0rt at hotmail dot com
New email:
PHP Version: OS:

 

 [2002-01-01 01:18 UTC] y0rt at hotmail dot com
session_register() doesnt seem to save anything in functions, eg.

session_start();

function bob() {
$var = "somethinghere";
session_register("var");
}

bob();
echo session_encode();

the above only registers the var name, not the data in it.

if it helps theres a way around it, all you gota do is make the $var global so instead of having $var have $GLOBALS['var'] and it works fine.

might be little bug, but it stuffed me up 4 nights in a row.

oh and the way i compiled php was just with apt-get install php4 in debian, (newbie here)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-10 17:31 UTC] bs_php at infeer dot com
This is not a Bug. All variables that you plan to register must be global!

Reason:
The PHP-function session_register() only  'remember' the *names* of the variables (not the content) it must save when the script terminates.
The session vars are read at script end. This happens outside of any function or methode and therefor only global vars that have been set have a value; all others are unset.
 [2002-01-10 17:35 UTC] derick@php.net
Indeed, not a bug, thx for explaining!. Please also note that you can use this in 4.1.x and higher:
$_SESSION['var'] = 'somethinghere';

It registers the session var 'var', whcih can be accessed through your whole script (in functions, or outside functions) as $_SESSION['var'].

Derick
 [2002-01-10 17:39 UTC] jan@php.net
no bugs can't be closed *nitpick* -> bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 17:01:33 2024 UTC