답변:
Boost 7.x 에서이 작업을 수행합니다. 예쁘지는 않지만 작업을 완료합니다.
function boost_page_delivery_callback_alter(&$callback, $set = FALSE) {
if ($callback == 'drupal_deliver_html_page') {
$callback = 'boost_deliver_html_page';
}
}
function boost_deliver_html_page($page_callback_result) {
global $_boost;
// Menu status constants are integers; page content is a string or array.
if (is_int($page_callback_result)) {
// @todo: Break these up into separate functions?
switch ($page_callback_result) {
// …
case MENU_ACCESS_DENIED:
// 403 page.
$_boost['menu_item']['status'] = 403;
break;
// …
}
// …
}
// …
}
Drupal 7에서 이미 설정된 HTTP 헤더를 반환하는 함수는 drupal_get_http_header () 이며 HTTP 헤더 이름을 매개 변수로 사용해야합니다. 보면 authorize_access_denied_page () , 및 drupal_fast_404 () 코드하면 해당 기능에 전달할 어떤 값 분명합니다.
// authorize_access_denied_page()
drupal_add_http_header('Status', '403 Forbidden');
watchdog('access denied', 'authorize.php', NULL, WATCHDOG_WARNING);
drupal_set_title('Access denied');
return t('You are not allowed to access this page.');
// drupal_fast_404()
if ($fast_paths && preg_match($fast_paths, $_GET['q'])) {
drupal_add_http_header('Status', '404 Not Found');
$fast_404_html = variable_get('404_fast_html', '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>');
// Replace @path in the variable with the page path.
print strtr($fast_404_html, array('@path' => check_plain(request_uri())));
exit;
}
"Status"헤더가 403으로 시작 하면 Drupal은 액세스 거부 페이지를 출력합니다.
전화 drupal_get_http_header('Status')가 늦게 발생 하는지 확인하십시오 . 호출하는 시간 hook_init()이 너무 빠르지 만 호출하는 동안 hook_page_alter()(또는 테마 사전 프로세스 후크) 호출하면 헤더 정보가 업데이트됩니다.
drupal_get_http_header('Status')경우을 반환합니다 NULL.
모듈이 " Default 403 (access denied) page" 값을 가로 채서 " "페이지에서 수정합니다 Administer > Site configuration > Error reporting:
에서 hook_enable사용 variable_get/ variable_set, 기존의 값을 복사 보조 변수와 자신에 의해 변수를 대체 (사용 등록하는 경로 hook_menu).
hook_form_FORM_ID_alter보조 변수를 읽고 쓰는 데 사용 하는 "오류보고"양식 을 변경합니다.
사용자가 완전히 보이지 않게하려면 페이지 콜백에서을 (를) 호출 할 수 drupal_goto( the_value_of_the_secondary_variable )있습니다.
이어 hook_disable, 값 복원 보조 변수에서를.
그리고 "액세스 거부"가 트리거 되면 모듈은 깔끔한 방식으로 (그리고 사용자에게 보이지 않는) 알림 을 받습니다 .
확실히 당신은 PHP의 get_headers()기능을 사용할 수 있습니까?
반환 된 배열의 첫 번째 요소는 응답 코드입니다. '403'이 포함 된 경우 Drupal은 "액세스 거부"페이지를 리턴했습니다.
전화하기 가장 좋은 곳이 어디인지 잘 모르겠습니다. 아마 hook_exit()당신의 필요에 따라 :
http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_exit/6
이는 Drupal 7에서 액세스 거부 (403) 및 페이지를 찾을 수 없음 (404)을 감지하는 가장 간단한 방법입니다.
// get the menu router item for the current page
$router_item = menu_get_item();
// if there is no router item, this page is not found
$is_page_not_found_404 = empty($router_item);
// if 'access' is empty for the router item, access is denied
$is_access_denied_403 = empty($router_item['access']);