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.
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:If you need to do it for non-node pages then you’ll want to implement
hook_init()instead:Both of the hooks are invoked well before the headers are sent to the client so either way will work.