gpt4 book ai didi

drupal - Drush状态: unrecoverable error caused by drupal_goto() in hook_init()

转载 作者:行者123 更新时间:2023-12-02 05:09:53 27 4
gpt4 key购买 nike

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

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

Drush 版本:7.x-4.4PHP 版本: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 服务器上失败。

最佳答案

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

使用 drupal_access_denied() 代替 drupal_goto()。如果您真的希望人们被重定向到另一个 url,那么可以在显示拒绝访问的页面上

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

现在,您应该做什么:一个模块,例如 Taxonomy Access (Lite) 或更合适的 Node Privacy By Role可用于授予对您的内容的访问权限。请注意,默认情况下, View 不会使用这些访问权限:它们将显示内容列表,而不管用户的访问权限如何:您必须重新配置所有 View 以遵守访问规则或完全不可访问,以某些角色。此外,您需要给“未成年人”一个单独的角色:这样您就可以授予他们与角色“经过身份验证的用户”甚至“成人”中的人不同的访问权限。您将需要一些机制来 automatically assign roles .

关于drupal - Drush状态: unrecoverable error caused by drupal_goto() in hook_init(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6825256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com