This topic is locked

PHPRunner and Drupal

1/2/2010 6:44:48 PM
PHPRunner Tips and Tricks
admin

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:


    <?php

    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 text in bold with your application URL.
3. In PHPRunner application add the following code to 'After application initialized' event:



$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"];

if ($data["rolename"]=='administrator')

$_SESSION["AccessLevel"] = ACCESS_LEVEL_ADMINGROUP;

else

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;

}

else

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;

}

else

// log out

{

session_unset();}

}


This code snippet assumes PHPRunner application shares database with Drupal. This is not a requirement though. If you want to keep databases separate - connect to Drupal database manually in the very beginning of 'After application initialized' event.
4. If your PHPRunner applications uses advanced security options or AfterSuccessfulLogin event you need to copy some code from login.php to 'After application initialized' event.
Open login.php file in any text editor and find the following section:

if($logged)

{

$_SESSION["UserID"] = $pUsername;

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;
...
if($myurl)

header("Location: ".$myurl);

else

header("Location: ".$defaulturl);

return;
}


Select and copy everything between $_SESSION["AccessLevel"] = ACCESS_LEVEL_USER; and if($myurl)

Paste it to the end of 'After application initialized' event;
This is it.

N
Nic 4/24/2010



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:
    Replace text in bold with your application URL.
  3. In PHPRunner application add the following code to 'After application initialized' event:



$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"];

if ($data["rolename"]=='administrator')

$_SESSION["AccessLevel"] = ACCESS_LEVEL_ADMINGROUP;

else

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;

}

else

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;

}

else

// log out

{

session_unset();}

}


This code snippet assumes PHPRunner application shares database with Drupal. This is not a requirement though. If you want to keep databases separate - connect to Drupal database manually in the very beginning of 'After application initialized' event.
4. If your PHPRunner applications uses advanced security options or AfterSuccessfulLogin event you need to copy some code from login.php to 'After application initialized' event.
Open login.php file in any text editor and find the following section:

if($logged)

{

$_SESSION["UserID"] = $pUsername;

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;
...
if($myurl)

header("Location: ".$myurl);

else

header("Location: ".$defaulturl);

return;
}


Select and copy everything between $_SESSION["AccessLevel"] = ACCESS_LEVEL_USER; and if($myurl)

Paste it to the end of 'After application initialized' event;
This is it.


URGENT !!!!!!

Hallo

I do not understand I'm Italian

please explain better by adding photos of the procedure

or

please explain better by adding video of the procedure

I'm sure his support will solve the problem

many thanks

M
memoday 8/10/2010

Dear Admin,
When you say 'article', do you mean 'block' as per Drupal terminology? I also come across the same issue here http://drupal.org/node/695986 and it seems the instructions are a bit different. In your instructions above, you said "In PHPRunner application add the following code to 'After application initialized' event:" while on the Drupal site it says "In your application add the following code to one of common include files.". The latter is not clear to me. Which one of common include files to add this code to?
Also, I will be using a different database. Can you please provide step-by-step instructions on this point? The statement above 'connect to Drupal database manually in the very beginning of 'After application initialized' event.' is not so clear to me.
Sorry to bother you with this and I look forward to hearing from you.
Thanks in advance for your great support.
Memoday

admin 8/12/2010

Memoday,
this is exactly the same instruction though wording is a bit different.

If you use PHPRunner follow instruction posted here.
If your question is how to connect to another database here is the link that can help:

http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/connect-to-mysql-database.aspx

M
memoday 10/14/2010

Thanks Admin for your reply. I managed to display the PHPRunner page in Drupal website, but how can I get rid of scroll bars in the frame page? Is there anyway to make it feel like a native Drupal page without scrolling bars? That would make things perfect. Any idea?

admin 10/15/2010

Make your iframe wide and high enough so scrollbars don't appear.

S
Seraph 10/27/2010

Hello, thanks for your work as usually
I have some problem.

I did all steps you signed but

In PHPRunner project I switch off the access with login (so the website is apparently without security)

When A user access to drupal website in node where I put the iframe he see the list_page of phprunner.
Now, Why in this way the user that enter on website don't have the rules that I set on "User Group Permission" window in the project?

I set as you say the groupID in this way:

$_SESSION["GroupID"] = $data["rolename"];


but seems that if I switch off the access with login (on security tab in phprunner) the rules that I set in "Permission" button don't work anymore...

any ideas?
Thank you very much!

admin 10/27/2010

Do not switch off login page in PHPRunner. Since logon process is automatic users will never see the login page.

S
Seraph 10/29/2010

Thank you very much!

Now it's work!

S
Seraph 11/4/2010

Hi at all!

I have another problem
I activate logs on AUDIT TRAIL menu

but trought the automatic login the logs on access are not registered.
I add this in the end of: "After application initialized"



if($auditObj)

{

$auditObj->LogLogin();

$auditObj->LoginSuccessful();

}


but It doesn't find the $auditObj object,

so I insert code:

$auditObj = GetAuditObject();


but nothing.
Any Ideas?

P
phenicie 1/28/2014

My login.PHP does not include the code mentioned. I am using PHP Runner 7.0 Build 19454 .
The section i believe that should contain that data looks like :

if ($d) {

//login succeccful

//run AfterSuccessfulLogin event

// if login method is not AD then ASL event fires in SetAuthSessionData



//redirect after success login

if($myurl)

header("Location: ".$myurl);

else

header("Location: menu.php");

return;

}

else

{

//invalide login

if($globalEvents->exists("AfterUnsuccessfulLogin"))

$globalEvents->AfterUnsuccessfulLogin($pUsername,$pPassword,$message, $pageObject);



if ($pageObject->message!=""){

$message = $pageObject->message;

}



if($message=="")

$message = mlang_message("INVALID_LOGIN");

}

}

else {

//invalide login

if($globalEvents->exists("AfterUnsuccessfulLogin"))

$globalEvents->AfterUnsuccessfulLogin($pUsername,$pPassword,$message, $pageObject);



if ($pageObject->message!=""){

$message = $pageObject->message;

}



if($message=="")

$message = mlang_message("INVALID_LOGIN");

}

}
T
tparkiDevClub member 2/18/2014

The latest versions of Drupal (7.26 for example) do not have the PHP Filter module as part of the core distribution. Thus you need to obtain and install the module currently in file php-8.x-1.x-dev.zip.