You are here: Home Development Joomla! Joomla!: Pass Session Data to a Wrapper
Joomla!: Pass Session Data to a Wrapper PDF Print E-mail
User Rating: / 8
PoorBest 
Development - Joomla
Written by Rick   
Monday, 23 February 2009 00:00

This information requires Joomla (1.5.x series) Global Configuration/System/Session Handler to be set to "database" and plugin "includePHP installed for the following information to be valid.

Current and active user sessions are stored in a cookie on the user local drive. The cookies are domain related (i.e.; when you lookup a cookie on your local system it's stored by the site name then cookie name). The following functions provide access to the Joomla cookie created during log-in;

  • session_name() represents the name of the cookie in the local system
  • session_id() contains the value of the cookie in the local system

The variables can be passed to external applications via php's setcookie() function that can be retrieved inside a Joomla wrapper for authentication purposes.

Cookie generation with php is as follows;

<?
//assign value to variables
$sid=session_id();
$sname=session_name();
$time=time()+3600;

//create-reset the cookie
setcookie("sessid",$sid, $time,"/");
setcookie("sessname",$sname, $time,"/");
?>

Note: Creating cookies with PHP is problematic. See http://microswamp.com/development/java/117-javascript-cookies to handle cookies with javascript.

Once session data is captured in the wrapper, the session_id() can be used to lookup the user in the Joomla table jos_session to verify the user is still logged into the system and the session has not been terminated by log-off or time-out. Further jos_session stores the user ID. Retrieving the user ID allows additional lookup and manipulation of the table jos_users. Information retrieved from jos_users can be used for additional security restriction based on user name, user type or group id. While not exactly within the Joomla core, this logic can provide granular ACR to wrapper applications.

The following code can be used to retrieve the stored cookie data;

<?
//display cookie data
echo "<h3>Demo - Capture cookie data and display.</h3>";
echo "Session ID: ".$_COOKIE['sessid']."<br />";
echo "Session Name: " .$_COOKIE['sessname']."<br />";

?>

If you are logged-in you can see a sample of the output for you session below;

Comments (0)
Write comment
Your Contact Details:
Gravatar enabled
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):S
:!::?::idea::arrow:
Security
Please input the anti-spam code that you can read in the image.