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?
No need to code: this is performed, with various settings available, by the existing login_destination module.
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)
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.