I have a PHP script that takes a database query and converts the results into an excel spreadsheet. The problem I'm having is using this script now within Drupal. Must this script be added to Drupal in order for it to work correctly?

If I link directly to it without adding it to Drupal, I can't seem to access any of the PHP session variables that otherwise are accessible just fine. The script relies on a few.

If I add this script into Drupal as a "page", which really it is not, then I get an error trying to load it and in the excel file it eventually generates are all parts of my site's HTML. Not at all a desired effect.

So the ultimate question is:

To run such a stand-alone PHP script, must I add it to Drupal and if so, is there some other custom content type for this?

Comments

dugawug’s picture

to answer my own question, no, the script must not be put in Drupal per se, but the following code can be put at the top which basically makes the script a Drupal page, and makes the Drupal session variables accessible:

require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

daddydo’s picture

Hi dugawug, I have the same situation and as I'm not a coder, I would kindly ask you to be a little more specific:
In what file I"ll put the code above and should I replace "includes" by the name of the php file to include. Could you give a more in depth example? Thanks a lot.