Tutorial: running a third party application in iframe

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
phprunner
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Dec 08, 2009 8:04 pm

Tutorial: running a third party application in iframe

Postby phprunner » Tue Dec 08, 2009 8:43 pm

Quite a few customers aske us to add Joomla integration to PHPRunner. Since this solution is quite generic I thought I would share it here.

The key is to display third party app in iframe. There are at least two ways to do so, com_wrapper component and one of iframe plugins. Besides that we need to make third party app login/logout automatically. This will be implemented by passing Joomla session id via URL.

1. Wrapper extension (com_wrapper).

Copy components/com_wrapper/views/wrapper/tmpl/default.php to templates/<your_template_here>/html/com_wrapper/wrapper/default.php. Default template in Joomla 1.5 is 'rhuk_milkyway' so you need to copy default.php to templates/rhuk_milkyway/html/com_wrapper/wrapper folder.

Modify com_wrapper/views/wrapper/tmpl/default.php the following way (see changes in bold).

We retrieve the current session id and pass it to PHPRunner application via URL.

defined('_JEXEC') or die('Restricted access');
$session =& JFactory::getSession();
$sid = $session->getId();

?>

...
name="iframe"
src="<?php echo $this->wrapper->url . "?sessionid=$sid"; ?>"
width="<?php echo $this->params->get( 'width' ); ?>"
...


Once you made this change create a new menu item in Joomla choosing Wrapper as a menu item type. Enter your application URL as a Wrapper URL. Make sure URL points to the start point of a third party app i.e. to http://localhost/myapp/index.php.

It doesn't really matter where third party app is located on the server.

2. Wrapper plugin.

Another approach is to use iframe plugin.

We'll need to implement a similar change in plugins/content/plg_iframe.php file. See changes in bold.

...
defined( '_JEXEC' ) or die();
$session =& JFactory::getSession();
$sid = $session->getId();


jimport( 'joomla.event.plugin' );

...

$params0['src'] = (@$params0['src'])? $params0['src']."?sessionid=$sid":$this->params->get( 'src', 'http://www.luyenkim.net' );
if($url !='') {
...



Now you can insert the following in any article:
{iframe width="600" height="500" align="top"}http://localhost/myapp/index.php{/iframe}



You can use any of methods above or even both methods together.

3. Add Joomla sessions support to your third party app application

Now we need to make your third party app understand Joomla session id.

Add the following code to one of common include files. This code needs to execute on every page load. The code sample below applies to PHPRunner.

Code: Select all


$jconn=db_connect();

// Get sessionvariable of Joomla-Session over the URL which passes the Joomla-Wrapper to the iframe
if (@$_GET["sessionid"])
  $_SESSION["sessionid"] = @$_GET["sessionid"];

if (@$_SESSION["sessionid"])
{

//Get the values out of the jos-session-table:

$rs=db_query("select * from `jos_session` where session_id='" . $_SESSION["sessionid"]. "'",$jconn);
$data=db_fetch_array($rs);
if($data)
// log in
{
   $_SESSION["UserID"] = $data["username"];
   $_SESSION["GroupID"] = $data["usertype"];
   if ($data["gid"]==24 || $data["gid"]==25)
      $_SESSION["AccessLevel"] = ACCESS_LEVEL_ADMINGROUP;
   else
      $_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;
}
else
// log out
{
   $_SESSION["UserID"] = "";
     $_SESSION["AccessLevel"] = "";
   $_SESSION["GroupID"] = "";
}

}


This will logon you to your application automatically. It will log out you automatically as well.

It's easy to see that the same approach can be applied to applications written in other languages like ASP.NET, ASP, Python etc.

Here is how it looks in action:
Image

More info on PHPRunner/Joomla integration. PHPRunner is a tool that builds nice looking PHP+MySQL websites.

User avatar
dizzi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3136
Joined: Fri Dec 21, 2007 9:36 pm
Location: Yorkshire, UK

Re: Tutorial: running a third party application in iframe

Postby dizzi » Tue Dec 08, 2009 9:45 pm

That's quite useful, thanks for sharing.
Freedom of expression ... some may try to suppress it but they can never take it away ...
There is no problem a good miracle can't fix.

aclhkaclhk
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Tue Aug 10, 2010 7:50 am

Re: Tutorial: running a third party application in iframe

Postby aclhkaclhk » Sat Jan 15, 2011 2:50 am

1. if i logout joomla, phpruner is logout automatically but how to logout phprunner and have joomla logout, too?

2. how to share or sync joomla user with phprunner user tables automatically when a new user register in joomla?

pls advise.


Return to “Joomla! 1.5 Coding”

Who is online

Users browsing this forum: No registered users and 7 guests