登录后,重定向到入口网址?

时间:2022-06-13 08:08:24

The site I'm working on is using the Frontpage module to redirect anon users to a login page. And I know about using triggers to set an action to redirect after login, (set to one specific url). But here's the catch:

我正在使用的网站是使用Frontpage模块将匿名用户重定向到登录页面。我知道在登录后使用触发器设置重定向动作(设置为一个特定的URL)。但这里有一个问题:

My users are each arriving at a different entrance url, eg: www.mysite/PersonsName

我的用户每个都到达不同的入口网址,例如:www.mysite / PersonsName

Is there a way to redirect back to the entrance url after login?

有没有办法在登录后重定向回到入口网址?

3 个解决方案

#1


No need to code: this is performed, with various settings available, by the existing login_destination module.

无需编码:现有的login_destination模块可通过各种设置执行此操作。

#2


you can put this code in your custom module implementing hook_user().

您可以将此代码放在实现hook_user()的自定义模块中。

function yourmodule_user($op, &$edit, &$account, $category = null)
{
  switch ($op) {
    case 'login':
      $_REQUEST['destination'] = $_REQUEST['q'];
    break;
  }
}

generally it's enough to set $_REQUEST['destination'] to you desidered destination page (this is what the module login_destination does i guess)

通常它足以将$ _REQUEST ['destination']设置为您想要的目标页面(这就是我猜的模块login_destination)

#3


You can take the URL and explode by "/" like this:

您可以使用URL并按“/”爆炸,如下所示:

$url =  explode("/",$_SERVER['REQUEST_URI']);

Then, set up a session to keep the username he accessed like this:

然后,设置一个会话以保持他访问的用户名,如下所示:

$_SESSION['used_name'] = $url[0];

And you can set up the page that he is being redirected to after the succesful login like this:

并且您可以在成功登录后设置他被重定向到的页面,如下所示:

$success_page = "yourpage/".$_SESSION['used_name'];

I hope this is what you were looking for.

我希望这就是你要找的东西。

#1


No need to code: this is performed, with various settings available, by the existing login_destination module.

无需编码:现有的login_destination模块可通过各种设置执行此操作。

#2


you can put this code in your custom module implementing hook_user().

您可以将此代码放在实现hook_user()的自定义模块中。

function yourmodule_user($op, &$edit, &$account, $category = null)
{
  switch ($op) {
    case 'login':
      $_REQUEST['destination'] = $_REQUEST['q'];
    break;
  }
}

generally it's enough to set $_REQUEST['destination'] to you desidered destination page (this is what the module login_destination does i guess)

通常它足以将$ _REQUEST ['destination']设置为您想要的目标页面(这就是我猜的模块login_destination)

#3


You can take the URL and explode by "/" like this:

您可以使用URL并按“/”爆炸,如下所示:

$url =  explode("/",$_SERVER['REQUEST_URI']);

Then, set up a session to keep the username he accessed like this:

然后,设置一个会话以保持他访问的用户名,如下所示:

$_SESSION['used_name'] = $url[0];

And you can set up the page that he is being redirected to after the succesful login like this:

并且您可以在成功登录后设置他被重定向到的页面,如下所示:

$success_page = "yourpage/".$_SESSION['used_name'];

I hope this is what you were looking for.

我希望这就是你要找的东西。