Using Drupal's PHP module, it is possible to build a page within the Drupal system and that works roughly as follows:

URI: domain/node/1

page structure:

drupal includes
drupal page elements before node
<my php code>
drupal page elements after node

The above sort of wraps the node containing the PHP code into Drupal.

What I would like to achieve is exactly the opposite: wrap Drupal with PHP:

URI: domain/directory1/file.php

page structure:

/*get to Drupal root*/
chdir("../");
ob_start();
include(drupalpage); //something that outputs a Drupal page with a dummy node prepared to contain markers so the resulting HTML can be split into header and footer to wrap the php code that follows
$drupalpage = ob_get_clean();
ob_end_clean();

// using the dummy node contents, split drupalpage into header and footer
$drupalheader=substr($drupalpage, 0, until node);
$drupalfooter=substr($drupalpage, from node, until end);

// get into the directory where our PHP system is
chdir("directory1/");

<do whatever our templated PHP system wants to do>

// wrap our PHP system output in drupalheader and drupalfooter
// for example:
$template->assign_vars(array('HEADER' => $drupalheader,'FOOTER' => $drupalfooter));

<output page from PHP system>

What URI should I use as include(drupalpage) to get the proper HTML output of the page?

Thank you for your help

Comments

DrupalDope’s picture

I'm so happy I figured it out myself :-)

first, the name of the php file that is used has to be added in .htaccess to the list of files to which direct access is allowed from HTTP

then, since include doesn't allow arguments, we can set the q variable in the GET array and then do the include:

$_GET["q"]="node/1";
include 'index.php';

that does the trick ;-)

the rest is straightforward