Hi
I had to let user get back to last visited page, just after log in; where the last visited page link contains anchors (example http://example.com/node/1#tab2)

After searching for a while, without finding a proper solution, I've come to this solution, which runs fine:

a) Add to the head of the page.tpl.php a client-side javascript function (called by the onclick event) which sets up a cookie with the clicked anchor. Example:

function  settab2()  {
  var date = new Date();
  date.setTime(date.getTime()+(1*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
  document.cookie = "iamhere"+"="+"#tabset-2"+expires+"; path=/";
  }

b) Store in $_SESSION the last page seen by the anonymous user. (you can add this to the same page.tpl.php ) Example:

global $user;
//set a "last page visited" for anonymous user , which are not on user access pages
if ($user->uid==0 && arg(0) !='user'  )  {
  $_SESSION['my_login_page']=$_GET['q'];
  }

c) Hack (I know is bad) the login_destination_redirect() function in login_destination.module.
I see the admin/user/login_destination let you insert some php snippets. I couldn't get it working, so I put this in the mentioned function.
Example:

function login_destination_redirect() {
/*
  $destination = variable_get('ld_url_destination', 'user');
  if (variable_get('ld_url_type', LOGIN_DEST_STATIC) == LOGIN_DEST_SNIPPET) {
    ob_start();
    $url = eval($destination);
    ob_end_clean();
  } else {
    $url = $destination;
  }
*/

  $url['path'] = $_SESSION['my_login_page'];
  $url['query'] = $_COOKIE['iamhere'];


  if (is_array($url)) {
    drupal_goto($url['path'], $url['query']);
  } else {
    drupal_goto($url);
  }
}

In this way, your user will be able to stay in the same page (and # anchor) after login

Please note that hack above is intended to only show a process to achieve the desidered behavior by Drupal.
Do not use this until you know what you are doing.

Do you think we will have something giving this feature in a future release of the module?

Comments

afagioli’s picture

Status: Active » Closed (fixed)

such a long inactivity... closed