By thrice on
I've created a page with a bit of PHP at the top. All I want that PHP to do is check a condition and deny access to the page if it's not allowed. I used code like this (ensuring the page has 'PHP content allowed'):
<?php
if( ! ..condition.. )
drupal_access_denied();
else
...all OK, I continue...
The thing is, this results in a page that's themed twice - I get the access denied page, but it's inside another page! It has two menus, two title banners, etc!
I could create a module and do the whole thing from PHP code, but this is a trivial check, and the page mechanism works well for it. Creating a module would be overkill.
Is there a neat way of actually redirecting users to a neat access denied page?
Comments
As you've found,
As you've found, drupal_access_denied actually prints the themed page. It doesn't say to deny access and show a page, it actually does so, and shows the page - in whatever context it happens to be in.
You'll be best to just wrap your page in an if().
You may try just 'return "go away"; ' as well - as an experiment, dunno what would happen.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Why
Why is the standard 403 error page not working for this? Which release are you on?
Nancy W.
now running 4 sites on Drupal so far
Drupal Cookbook (for New Drupallers)
NancyDru
5.1
I'm using Drupal-5.1. The drupal_access_denied function sets the 403 header, then returns the content page which is themed. It's not designed to be called from code in a page, it would appear.
my work around = fake access denied page
if (user_access('can do this')) {
echo "real page";
} else {
drupal_set_title('Access denied');
echo "You are not authorized to access this page.";
}
- bottmanbros.com
- bbros.us -
Who else is interested in Lunch?