3

I have a module with a drupal_goto() that redirects users if they don't pass the age requirements (wine site) in hook_init(). The module is set with a heavier weight so it loads last.

On PHP 5.3, drush update fails. The same code and DB on a different server with PHP 5.2 runs fine.

Drush version: 7.x-4.4 PHP version: 5.3 example:

When I run: drush status, I get an error. Here is the output with the debug and verbose flag.

$ drush -d -v status
Bootstrap to phase 0. [0.02 sec, 2.47 MB]                            [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.03 sec, 2.67 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.06 sec, 5.49 MB]                                              [bootstrap]
Initialized Drupal 6.22 root directory at /var/www/example.com/public_html [0.07 sec, 6.28 MB]                         [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.07 sec, 6.29 MB]                                              [bootstrap]
Initialized Drupal site default at sites/default [0.07 sec, 6.29 MB]                                                       [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [0.08 sec, 6.29 MB]                                     [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_database() [0.08 sec, 6.33 MB]                                          [bootstrap]
Successfully connected to the Drupal database. [0.08 sec, 6.33 MB]                                                      [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_full() [0.09 sec, 6.67 MB]                                              [bootstrap]
Drush command terminated abnormally due to an unrecoverable error. [0.34 sec, 31.38 MB]                                 [error]

The question is now: Why does the drupal_goto() cause drush to fail on the PHP 5.3 server and not the PHP 5.2 server.

Coder1
  • 13,139
  • 15
  • 59
  • 89
  • Update: drush status runs on one drupal 6 install on this server, but on all others, i get that error. just can't figure out how to debug this issue. – Coder1 Jul 26 '11 at 16:39
  • what version of drush is this? Can you confirm that the drupal install is valid (i.e. can you navigate to it in a browser)? Can you run the same command with --verbose as well? – wiifm Jul 27 '11 at 10:46
  • I updated the question with all the info you requested, including running a new status with -d -v. Added some additional notes. With the help of someone on do, I am beginning to suspect some incompatibility between one of the modules and PHP 5.3, ... although I get no errors in the log when running the site. – Coder1 Jul 27 '11 at 15:37

1 Answers1

0

You should not issue redirects when there is an access denied. That is a logical error in any web-framework. You should issue an "access denied" when you want to deny access. Just like you issue a "the content has moved there, please go there" when your content has moved.

Instead of drupal_goto(), use drupal_access_denied(). If you truly want people to be redirected to another url, the place to do that, would be on the page that shows the denied access.

That said, issuing a drupal_access_denied(), or, in fact, sending any header in hook_init() is plain wrong. From the documentation: «Perform setup tasks.» Sending headers is not a setup-task. Moreover, that same documentation warns about another potential problem with your approach: «This hook is not run on cached pages», in other words, once an adult visits a page, and it is cached, underaged visitors will not be redirected or denied access, they will get the cached page served.

Now, on to what you should do: A module such as Taxonomy Access (Lite) or the more appropriate Node Privacy By Role can be used to grant access to your content. Note that, by default, Views will not use these access: they will show lists of content, regardless of the access by the user: you will have to reconfigure all your views to either honor the access-rules or to be inaccassible entirely, to certain roles. In addition, you need to give "minors" a separate role: that way you can grant them different access then the people in rol "authenticated user" or even in "adult". You will need some mechanism to automatically assign roles.

berkes
  • 26,996
  • 27
  • 115
  • 206
  • I appreciate the thought that went into your answer, but you are answering a question that wasn't asked while making way too many assumptions about the app, its content, how the content is delivered, and the module that controls the age access. There's just absolutely no need for the modules you are recommending. For example, users are anon, content is public, and the access denied won't always be because an age was not verified. Might be good suggestions for someone building an authenticated user based app though. – Coder1 Aug 11 '11 at 15:43
  • Just a note: you can use `if (!function_exists('drush_main')) { ... }` to check if you're in drush environment – kolypto Jan 17 '13 at 10:52