I'm writing a custom module for Drupal 6, and I need to execute some PHP no matter which page the user accesses.
I see that hook_init is not run on cached pages, so that's a no-go. hook_boot doesn't work, either, because it happens too early in the page request to let me use some functions I need.
So I was thinking about specifying a block using hook_block, but that hook just makes me pull my hair out:
function test_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
case 'list':
$block['test_block']['info'] = t('Test block');
return $block;
case 'view':
$block = array();
switch ($delta) {
case 'test_block':
$block_content = '<?php echo \'WTF?\'; ?>';
$block['subject'] = NULL;
$block['content'] = $block_content;
break;
}
return $block;
}
}
This renders as:
<div class="content">
<!--?php echo 'WTF?'; ?-->
<a id="context-block-test-test_block" class="context-block editable edit-global"></a>
</div>
Obviously, that's not what I'm looking for, either. Why does the PHP in that block not render correctly? Even if I end up using something other than a block to solve my problem, this issue really sparks my curiosity.
If I can't use hook_block, how do I get some PHP to run on every page? I need access to the $user global and to the drupal_goto() function.