3

我有一个带有 drupal_goto() 的模块,如果用户没有通过 hook_init() 中的年龄要求(葡萄酒网站),它会重定向用户。该模块设置了较重的重量,因此最后加载。

在 PHP 5.3 上,快速更新失败。使用 PHP 5.2 的不同服务器上的相同代码和数据库运行良好。

Drush 版本:7.x-4.4 PHP 版本:5.3 示例:

当我运行: drush status 时,我得到一个错误。这是带有调试和详细标志的输出。

$ 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]

现在的问题是:为什么 drupal_goto() 会导致 drush 在 PHP 5.3 服务器而不是 PHP 5.2 服务器上失败。

4

1 回答 1

0

当访问被拒绝时,您不应发出重定向。这在任何网络框架中都是一个逻辑错误。当您想拒绝访问时,您应该发出“拒绝访问”。就像您在内容移动时发出“内容已移动到那里,请到那里”一样。

而不是drupal_goto(),使用drupal_access_denied(). 如果您真的希望人们被重定向到另一个 url,那么执行此操作的位置将在显示拒绝访问的页面上

也就是说,发出一个drupal_access_denied(),或者实际上,发送任何标头hook_init()是完全错误的。来自文档:«执行设置任务。» 发送标头不是设置任务。此外,该文档还警告您的方法存在另一个潜在问题:«This hook is not run on cached pages»,换句话说,一旦成人访问一个页面,并且该页面被缓存,未成年访问者将不会被重定向或拒绝访问,他们将获得服务的缓存页面。

现在,您该做什么:可以使用诸如分类访问(Lite)或更合适的节点隐私之类的模块来授予对您的内容的访问权限。请注意,默认情况下,视图不会使用这些访问权限:它们将显示内容列表,而不管用户的访问权限如何:您必须重新配置所有视图以遵守访问规则或完全不可访问,以某些角色。此外,您需要给“未成年人”一个单独的角色:这样您就可以授予他们不同的访问权限,然后是“经过身份验证的用户”甚至“成人”中的人。您将需要一些机制来自动分配角色

于 2011-08-11T12:32:11.623 回答