Quite a few customers aske us to add Drupal 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. Besides that we need to make third party app login/logout automatically. This will be implemented by passing Drupal session id via URL. This tutorial applies to Drupal 7.x and PHPRunner 5.1 or better. Should work the same way with earlier versions of Drupal.

1. Enable PHP filter

'Configuration and modules' menu, 'Modules' tab. Enable 'PHP filter'.

2. Create a new article in Drupal

Use 'PHP code' as text format. Paste the following code to the body:

global $user;
echo '<p><iframe scrolling="auto" src="http://localhost/drupal7/phprunner/carsadmin_cars_list.php?sessionid='. @$user->sid .'" style="border-style: hidden; width: 100%; height: 500px;"></iframe></p>';

Replace http://localhost/drupal7/phprunner/carsadmin_cars_list.php with your application URL.

3. In your application 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 though SQL query will be exactly the same for any other app.

$dconn=db_connect();

if (@$_GET["sessionid"])
  $_SESSION["sessionid"] = @$_GET["sessionid"]; 


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

//Get the get username/role from the database

$sql="select u.*,s.*,ur.rid, r.name as rolename 
from sessions s 
inner join users u on s.uid=u.uid 
left outer join users_roles ur on u.uid=ur.uid 
LEFT OUTER JOIN role r ON r.rid = ur.rid 
where u.status=1 and u.uid>0 and s.sid='" . $_SESSION["sessionid"]. "'";
$rs=db_query($sql,$dconn);

$data=db_fetch_array($rs);

if($data)
{
	$_SESSION["UserID"] = $data["name"];
	if (!is_null($data["rolename"]))
	{
		$_SESSION["GroupID"] = $data["rolename"];
        }
}
else 
// log out
{
	session_unset();}
}

This is it.

More info on PHPRunner/Drupal integration. PHPRunner is a PHP code builder that creates nice looking PHP/MySQL websites.