[mambo] Howto add session variables to Mambo 4.5.x
Hans Kaspersetz
hans at cyberxdesigns.com
Sat Jul 9 01:38:23 EDT 2005
I recently faced with the need to add two session variables to Mambo.
Searching the Internet I found a couple of resources but no straight
forward directions on how to add them and access them. I thought that I
would write up my experience and submit it for comment. Chris Hendry
helped me figure this out. So thank you Chris for your help, thank you
Mitch and thank you Mambo. We use Mambo all the time and love it.
You are going to have to complete two tasks to add session variables.
First task is to add a column to the session table in the data base.
The second is add the variables to the session class to handle the data
work.
So, Mambo uses a custom session handler that stores the session data in
the database. Each session variable has an associated column in the
database so I started by adding a column to the database using the MySQL
ALTER command. Mambo session data is stored in mos_session table. Take
note, the name of the column will exactly match the name of the session
variable.
You will need to be able to use the MySQL command line interface or have
access to phpMyAdmin or some other client that lets you run SQL directly
on the db. You will also need to have a user with the privileges to
ALTER the database.
Sample ALTER command:
ALTER TABLE `mos_session` ADD [column definition] AFTER `gid`
The second step in the process is adding the session variables to the
class that handles sessions in Mambo. I have to take this opportunity
to state that modifying the core makes it unsupportable by the Mambo
crew. In other words, you will have to hand patch the files that you
modify to ensure that the patches that come out of Mambo do not
overwrite your changes. What does that mean, running a diff against
your files and the Mambo patch files and figuring out how to apply their
changes. Enough of that rant.
Open the file /includes/mambo.php and find the class mosSession extends
modDBTable. This will be on or about line 2037. You will see a list of
variables:
var $usertype=null;
/** @var string */
var $username=null;
/** @var time */
var $gid=null;
/** @var int */
var $guest=null;
/** @var string */
var $_session_cookie=null;
You will need to add your variable after the original Mambo session
variables. For example:
var $guest=null;
/** @var string */
var $_session_cookie=null;
/** @var string */
var $newMamboSessionVar='foo';
Please take care to name your session variable exactly the same thing
you named your new column in the table.
Now figure out where you need to use your session variable and access it
through this object:
$mainframe->_session->newMamboSessionVar
if you want to change the value of the object do this:
$mainframe->_session->newMamboSessionVar = 'bar';
$mainframe->_session->update(); //The update method commits the change
to the session store.
I think that is it. As long as $mainframe is in scope you should be
ok. I can't recall off hand a place in Mambo that mainframe is not in
scope and if it isn't just add it to the global list at the top of the
function.
I look forward to feed back from the NYPHP Mambo crew. If I am wrong or
have made a mistake please let me know.
Thanks,
Hans
--
Hans C. Kaspersetz
Cyber X Designs
New York PHP
http://www.cyberxdesigns.com
http://www.nyphp.org
More information about the Joomla
mailing list