Restrict node for anonymous user programmatically
hook_init:

&lt;?php
// Get the current active node object if present.
$node = menu_get_object();
// Redirect to login page if NID == 42 and user is anonymous.
// User will then go back to node page due to destination being set.
if (   user_is_anonymous() 
    &amp;&amp; !empty($node) 
    &amp;&amp; !empty($node-&gt;nid) 
    &amp;&amp; $node-&gt;nid == 42
    ) {
  drupal_goto('user/login', array('query' =&gt; array('destination' =&gt; 'node/' . $node-&gt;nid)), 307);
}
?&gt;


hook_boot:

&lt;?php
$args = arg();
if (   user_is_anonymous()
    &amp;&amp; isset($args[0]) &amp;&amp; $args[0] == 'node'
    &amp;&amp; isset($args[1]) &amp;&amp; is_numeric($args[1])
    ) {
  drupal_goto('user/login', array('query' =&gt; array('destination' =&gt; 'node/' . $node-&gt;nid)), 307);
}
?&gt;