after login, redirect to entrance url?

2019-07-03 03:54发布

问题:

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?

回答1:

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



回答2:

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)



回答3:

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.



标签: drupal