如何解决登录后更改重定向路径
我想更改 drupal 7 中所有用户的重定向成功页面。
我在成功登录后在 mysite.com/user
中的登录页面被重定向到页面 mysite.com/user/1
.butr 我想将登录成功重定向页面更改为
mysite.com/node/1
我试过了
function bartik_user_login(&$edit,$account)
{
// Your logic will set $redirection to the desired location
$redirection = 'node/1';
// Unless there is already a redirection going,or the user is trying to reset his password,we redirect to $redirection.
if (empty($_GET['destination'])
&& !is_null($redirection)
&& (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset'))
{
$_GET['destination'] = $redirection; // Should we use $edit['redirect'] instead..?
}
}
解决方法
因为 $_GET['destination']
始终存在(在您的情况下为 user/{id}
),因此您的分配 $_GET['destination'] = $redirection
永远不会到达。
只需从 empty($_GET['destination']
条件中删除 if
,您的代码就会起作用:
function bartik_user_login(&$edit,$account)
{
$redirection = 'node/1';
if (!is_null($redirection)
&& (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset'))
{
$_GET['destination'] = $redirection;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。