• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1020
  • Last Modified:

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











0
egoselfaxis
Asked:
egoselfaxis
  • 4
  • 3
1 Solution
 
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
 
egoselfaxisAuthor Commented:
Yes - that worked exactly the way I needed it to.

Thanks for your help!

- yg
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now