Using drupal_access_denied()
Hi, Although I've managed to implement some functionality using Rules, for various reasons I'd like to shift it to some logic and code in my own custom module that prevents access to certain pages. Doing: function mymodule_preprocess_page(&$vars) { if ($some_condition) { print "pass"; } else { print "fail"; } } works fine. If I do: function mymodule_preprocess_page(&$vars) { if ($some_condition) { drupal_access_denied(); exit; } } I just get a white page (which is a 403 page looking at the header, not a 500). What do I need to do instead? Cheers, David
Hi, By the time you get to preprocess_page it's probably too late for drupal_access_denied, for the same reasons as drupal_add_js doesn't work in preprocess_page functions (see http://www.drupaler.co.uk/blog/joys-preprocessing/70), perhaps you might need to use hook_menu_alter instead and override the access callback? Lee
If I do:
function mymodule_preprocess_page(&$vars) { if ($some_condition) { drupal_access_denied(); exit; } }
I just get a white page (which is a 403 page looking at the header, not a 500).
participants (2)
-
David T -
Lee Rowlands