Question: How to use sessions in Joomla! 1.5 using the Joomla! API

 

Answer:

  • This can be obtained using the JFactory/getSession object
  • Instantiate the getSession object
    View source
    $session =& JFactory::getSession();
    There are a couple of parameters that you can pass with this object. They are
    • name - The session name
    • id - Unique ID of the session
    • expire - Expiry date and time
    • security - Comma seperated security options, have a look at JSession
  • Now we set the session
    View source
    $session->set( 'mySession', 'sessionValue' );
  • We get the session variable as follows
    View source
    $session->get( 'mySession' );
NOTE: For more information refer to the Joomla! API documentation.