Page 1 of 1

Adding some variables to Joomla's session

Posted: Sat Oct 20, 2007 10:01 pm
by martinstender
Hi all

I'm doing a custom component, that would allow special users to log in to a private admin area. These users are not normal Joomla users, but exits in another table. Everything works, but I can't seem to do normal php-session stuff (like checking if a certain session variable exist and clear that variable on log-out - ie. unset($_SESSION['myVar']) etc. etc. ).

Is there special woodoo required for stuff like that in Joomla-land?

Thank you in advance!
Martin

Re: Adding some variables to Joomla's session

Posted: Sun Oct 21, 2007 5:42 pm
by martinstender
Hi, it's me again ....
I found this tutorial, that really is for Mambo 4.5.x (http://lists.nyphp.org/pipermail/joomla ... 00261.html).

So I went through the steps - expanded the session-table in the db with a test-column, added an identically named variable in joomla.php (around line 700, not 2037 as in Mambo.php).
Then in my component, I do this _session->myNewSessionVar ='test'; $mainframe->_session->update(); ?>.
So far so good. I can now print out that variable by adding _session->myNewSessionVar ?> somewhere in index.php for example.
BUT, when I go to another page, I can't read out the new variable.
I thought that new variable would be registered in the session and stay there as long as the session lives or until I unset it.

Any ideas?
Thanks in advance
Martin
(Using Joomla 1.0.11)

Re: Adding some variables to Joomla's session

Posted: Wed Oct 24, 2007 7:52 pm
by ianmac
Try $mainframe->getUserState(), $mainframe->getUserStateFromRequest and $mainframe->setUserState().

Look at the includes/joomla.php for more information on these functions.

You have to put global $mainframe; at the top of your function.

Ian