Is there a way to see what the HTTP status code is for a given page in Drupal?

For example, if I land on an access denied or page not found, can I see that in a status code and use it?

I am using Contexts to set block layouts, but on a 403/404 page, I don't want to show blocks. The same thing goes for Views- for some reason the pages are not redirecting to my custom error page, so setting ~path is not working.

I know there is a Context Error module that sets context if the page is 403 or 404, but I want to do the opposite, where the context is active IF the page is neither a 403 or 404, so I need to check the headers, not the path.

Edit: Unless there is a part of Context that I am missing to check page/view access?

1 Answer 1


To fix this in context you should be able use context error to create a context; then, create a separate context which only applies if that context is not set.

To check the status code in code you can see what is returned by drupal_get_headers()

  • drupal_get_headers() was only showing me charset and content type.
    – Kevin
    May 10, 2011 at 16:44
  • if 'drupal_access_denied()' is called then it should set an error visible in drupal_get_headers. Do you know how the error is being generated, is it standard permissions? May 10, 2011 at 16:51
  • It's generated from an Access setting in a View.
    – Kevin
    May 11, 2011 at 13:36
  • I'm also using Pressflow
    – Kevin
    May 13, 2011 at 16:34
  • I moved my code from hook_init to hook_footer with better results.
    – Kevin
    May 14, 2011 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.