2

I thought I could use the following code:

<a href="user/login?destination=<?php print token_replace('[current-page:url]'); ?>a link</a>

to redirect users to the page they were on after log in, but it doesn't seem to work.

I can see the correct url on the login page, e.g.:

mysite/user/login?destination=the url of the page I was on

but when I login I am still redirected to mysite/users/my user name.

  • 1
    Where are you placing the code? – Triskelion Jun 3 '13 at 23:39
  • I'm placing the code in a block, where all the other code works ok – olisb Jun 4 '13 at 9:38
1

If you want to Redirect to previous drupal page after login, you can try this.

print l("Login","user/login",array('query' => drupal_get_destination()));

see drupal_get_destination

  • Top tip, thanks, but actually my 'link' is an image... how would I call the image instead of the "Login" text? – olisb Jun 5 '13 at 18:03
  • thanks @nikhil-m I found out that you can put an image in a l() by using 'html' => true, Thanks to api.drupal.org/api/drupal/includes!common.inc/function/l/7 so what i ended up with is: print l('<img src="path-to-image.png" title="A title here">',"user/login",array('query' => drupal_get_destination(), 'html' => true, )); – olisb Jun 6 '13 at 13:15
  • @user2337605 thanks for the info. i will update the answer – niksmac Jun 6 '13 at 13:25
0

You can use Token Filter module and the following code should work:

<a href="user/login?destination=[site:current-page:path]">a link</a>

Make sure that the token filter is available in the text format you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.