after login, redirect to entrance url?

2019-07-03 03:59发布

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:

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

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

标签: drupal
3条回答
Juvenile、少年°
2楼-- · 2019-07-03 04:27

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

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

查看更多
小情绪 Triste *
3楼-- · 2019-07-03 04:37

you can put this code in your custom module implementing 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)

查看更多
Lonely孤独者°
4楼-- · 2019-07-03 04:42

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

查看更多
登录 后发表回答