代码之家  ›  专栏  ›  技术社区  ›  Kevin

为某些节点发出403

  •  4
  • Kevin  · 技术社区  · 14 年前

    如何为某些节点发出403?我尝试使用Drupal_访问被拒绝。当我收到拒绝访问的消息时,看门狗充满了:

    无法修改邮件头信息-邮件头已发送

    这是正常的吗?我是否没有使用Drupal_访问权被拒绝?

    1 回复  |  直到 14 年前
        1
  •  6
  •   user113292    14 年前

    hook_nodeapi()

    $op = load

    $op = view

    function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
      switch ($op) {
        case 'view':
          drupal_access_denied();
          exit();
          break;
      }
    }
    

    hook_init()

    function mymodule_init() {
      $nodes_403 = array(42, 69, 187);
      if (arg(0) == 'node' && in_array(arg(1), $nodes_403))
        drupal_access_denied();
        exit();
      }
    }
    

    node access rights

    hook_access()

    function mymodule_access($op, $node, $account) {
      $nodes_403 = array(42, 69, 187);
    
      if (in_array($node->nid, $nodes_403)) {
        return FALSE;
      }
    }
    

    access callback

    function mymodule_menu_alter(&$items) {
      $items['node/%node']['access callback'] = 'mymodule_access';
    }
    
    function mymodule_access($op, $node, $account = NULL) {
      $nodes_403 = array(42, 69, 187);
    
      if ($op == 'view' && in_array($node->nid, $nodes_403)) {
        return FALSE;
      }
    
      return node_access($op, $node, $account);
    }
    

    hook_menu_alter()