You are right I was thinking you pass $x but actually you just pass the name x.
Anyway I'm just trying to write my own session functions. Primarely to use a database instead of the file based sessions that are available through php. I know that I can add handlers to php to use a different back end but I guess I want to understand what is actually going on under the hood so I'm diving in a little deeper.
This is what I was looking for. Just a basic way to add variable/value pair and create a serialized string which can be stored in a database, and then extracting the variable/value pairs and then making the variables available as they were before.
Basically just what the php functions do but I guess at the first principle level.
Is there an advantage to using the php session_register() functions as opposed to writing your own?
function bp_session_register($var)
{
//globalize the passed in variable and the session data array.
global $sess_data,$$var;
//add,overwrite variable name / value pair
$sess_data[$var]=$$var;
//normally we would write to database
//bp_session_write(serialize($sess_data));
}
function bp_session_start($sess)
{
//normally we would read the serilized session data from the database
//$sess_data=bp_session_read(serialize($sess_data));
global $sess_data;
while (list($var,$value) = each($sess_data))
{
global $$var;
$$var=$value;
}
}
$name="radek";
bp_session_register("name");
$id=23;
bp_session_register("id");
print("<br>TEST2: NAME=$name, ID=$id");
unset($name);
unset($id);
//this should have no value as variables are unset
print("<br>TEST3: NAME=$name, ID=$id");
//this should reinitialize the variables
bp_session_start(3);
print("<br>TEST4: NAME=$name, ID=$id");