Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:19:31+00:00 2026-06-14T13:19:31+00:00

DETAILS I can use user state variables to store and retrieve data in Joomla

  • 0

DETAILS

I can use user state variables to store and retrieve data in Joomla sessions.

EXAMPLE set variable

$app =& JFactory::getApplication();
$app->setUserState( 'myvar', $myvarvalue );

but I can also store and retrieve variables in session using JFactory/getSession.

EXAMPLE set variable

$session =& JFactory::getSession();
$session->set('myvar', $myvarvalue);

QUESTIONs

What is the difference between the two methods?
When should I use one over the other?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:19:32+00:00Added an answer on June 14, 2026 at 1:19 pm

    In short: it’s not a big difference and you can use whatever feels right in the context. I would stick with JApplication/setUserState because I think the code is better self explanatory.

    The actual difference:

    Both methods will store the specified state in the session. JApplication/setUserState will in fact internally use JSession/set to store the state.

    What JApplication/setUserState does differently is that it will store every key value pair in a JRegistry. So it is equal to:

    $session = JFactory::getSession();
    $registry = $session->get('registry');
    $registry->set('myvar', $myvarvalue);
    

    So what’s the point of using a JRegistry? It’s the pretty much the functionally provided JRegistryFormat. You can use it to both parse and format the state:

    $session = JFactory::getSession();
    $registry = $session->get('registry');
    $json = $registry->toString('JSON');
    $xml = $registry->toString('XML');
    

    It’s also worth pointing out that using JApplication/setUserState your state will end up in the “default” namespace:

    $app = JFactory::getApplication();
    $app->setUserState( 'myvar', $myvarvalue );
    // $_SESSION['default']['registry']->set('myvar', $myvarvalue)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use data binding on a details form to add a new
I have a page which displays a form that a logged-in user can use
I am writing an app that will use Reverse Geocoding to translate the user's
I can use the following syntax in a Jet (mdb) query to select data
I use this code to redirect user to a particular app in the Market:
My Adobe Flex app relies on taking a user's details from Facebook, which will
Can someone explain to me in detail when I must use each attribute: nonatomic
Anyone can explain in details what the following macro does? #define write_XDATA(address,value) (((char *)0x010000)
How can i get song details to play from sdcard and complete the action
Can anyone provide details on what the three of these mean? System::ContainerStartTime System::CreationDate System::StartTime

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.