Accessing / updating Joomla Session/User variables

I've recently updated the "jos_users" table in the MySQL database for my joomla site with a new column named "skintype" .. and am successfully accessing and displaying it's value using the following:

<?php
$user = & JFactory::getUser();
echo $user->get( 'skintype' );
?>

I've added a page to my site which updates this "skintype" value in the database, and need to figure out how to also update the value that's contained within $user->get( 'skintype' );

How can accomplish this?  Is there any way that I can do it without requiring that the user first log out of the website and then log back in?   If so, how?

Thanks,
- Yvan











egoselfaxisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

karoldvlCommented:
In this part:
"I've added a page to my site which updates this "skintype" value in the database, and need to figure out how to also update the value that's contained within $user->get( 'skintype' );"

do you mean you need to update the "skintype" for the current user only (like selecting a skin in the control panel for the current user) or in general (f.e. admin user changing "skintype" for arbitrary user)?

The former should be quite straightforward, the latter would potentially impede performance drastically.
0
egoselfaxisAuthor Commented:
By "skintype"  I do NOT mean "theme".  On my site, "skintype" refers to an actual property that's assigned to an individual user, .. just like a name, email address, username or password.  

When the user logs in to the website, many of these values (including the skintype) are retrieved from the database and then stored in a session variable, which makes them available to display within my custom template.  However, .. when any of these values are updated in the database, they are not automatically updated within the session variable(s).  The user has to first log out and then log back in to see the updated values.  

So I'm just trying to figure out how to force an update to the session variable that contains the skintype value, so that upon the next page refresh, the user will see the updated skintype value (which I am displaying in the upper righthand corner of my custom template).  The problem is -- not only do I not know what the session variable name is -- but it's my understanding that you can't read and write session data the way you'd normally expect to when you're working within the Joomla framework. The syntax is apparently different.  

Please advise.  

Thanks!
- Yvan
0
karoldvlCommented:
OK, but there are two possibilities here.

1) The change to the "skintype" value occurs only due to direct user action. For example he goes to some page, he clicks on something, changes settings etc. This way your problem is to refresh the session variable when this occurs. Should be quite easy to do correctly.

2) The change to the "skintype" can occur "any time". Let me be user A, I'm logged in, doing something on this website. In the meantime user B (probably admin/moderator) initiates an action which changes user A's "skintype". Desired behaviour would be that user A will get the new value on the very next page hit. This is no easy feat or it will require validating this value on every page generation (reload). This can influence performance (depending on your particular situation).

If it's #1, then it's only matter of syntax & available methods. I would have to take a look at Joomla (not used it for quite a time) to give you precise info. If it's #2, then the easy way is to make an additional validation (+1 database query per page). The hard way would require thinking outside the box (at the moment I'm not even sure how this could work) - hope that's not what you need.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

egoselfaxisAuthor Commented:
It's scenario #1 -- where the user goes to a page, ... fills out and submits an online survey, ... and at the end of the survey, the user's skintype value gets updated in the database.  

- yg

 
0
karoldvlCommented:
OK, it will take me a while to get through Joomla code. I'll be back with this shortly.
0
karoldvlCommented:
Are you able to inject some new code at the point of database update (survey submission)?

If so, it seems like there's nothing more than to use set method to update the property:

$user = & JFactory::getUser();
echo $user->get( 'skintype' );
$user->set('skintype', 'new');
echo $user->get( 'skintype' );

Am I missing something here? Some constraints I'm not aware of?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
egoselfaxisAuthor Commented:
Yes - that worked exactly the way I needed it to.

Thanks for your help!

- yg
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web-Based CMS

From novice to tech pro — start learning today.