0
votes

My Drupal 6 installation has the php filter disabled so I can't use <?php ... ?> in the node itself.

I have a case where I need to run a little bit of PHP code on a small number of pages. Is there a way in Drupal 6 to create a module that will match a URL pattern and then before showing the page execute a function?

Specifically, on a few pages I need to process some data and then send an HTTP header. I know that I can create a custom .tpl file for these pages but putting application logic like this in a .tpl file feels like a hack.

1

1 Answers

1
votes

If you want to do this specifically for node pages then you'd be better off implementing hook_nodeapi(). This would mean you don't have to perform a match based on the URL and you can add your header in the most 'structured' manner possible:

function MYMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if ($op == 'view') {
    drupal_set_header('some header');
  }
}

If you need to do it for non-node pages then you'll want to implement hook_init() instead:

function MYMODULE_init() {
  if ($_GET['q'] == 'node/1') { // or whatever path
    drupal_set_header('some header');
  }
}

Both of the hooks are invoked well before the headers are sent to the client so either way will work.