How to i programatically change the page thats loaded from hook_init? I am in the process of building a drupal module that will block access to certain IP addresses, i've built the whole thing and it works a treat except from one area of functionality; i would like to be able to redirect blocked users to a node.

The code that i have does everything except display the node:

if (variable_get('lock_denied_response_type') == 2){
  $node_id = variable_get('lock_denied_node');
  $node = node_load($node_id);
  $node_view = node_view($node, FALSE, TRUE);
  drupal_render_page($node_view);
  exit;
}
else{
  echo variable_get('lock_denied_html');
  exit;
}


I've scanned google, stack overflow etc but not much luck. So far as i can tell, it appears my approach is wrong and rather than triggering my own render page, i should just change which node the standard rendering process uses, something like this:

if (variable_get('lock_denied_response_type') == 2){
  $node_id = variable_get('lock_denied_node');
  /* insert awesome node override code here */
}
else{
  echo variable_get('lock_denied_html');
  exit;
}


Suggestions?

Cheers!
you can do somthing like this:

function MY_MODULE_init() {
    global $user;

    // or you can also use ip_address() function
    if($user-&gt;hostname == 'MY_BLOCKED_IP') {
      drupal_goto('node/NID_OF_IP_BLOCKED_NODE');
    }
  }


2-aproach (this is a recommended way. Because hook_init() will be removed from drupal v8):

// in template.php
function MY_THEME_preprocess_page(&amp;$variables) {
  if($variables['user']-&gt;hostname == 'BLOCKED_IP') {
    drupal_goto('node/NID_OF_IP_BLOCKED_NODE');
  }
}