I have added flag links to content pages for anonymous user. When user clicks on that link, the user should be redirected to user login page but after successful login the user should be redirect to last visited page.
I have used this code of a previously posted thread:
<?php
global $user;
if(!$user->uid) {
// $flag: bookmark or make_feature, $action: flag, $content_id: $nid.....
$flag_link = flag_flag_link($flag, $action, $content_id);
$flag_link = flag_flag_link($flag, $action, $content_id);
$flag_url = $flag_link['href'];
//echo implode("/",arg());
if(isset($flag_link['query']['token'])) {
$flag_url .= '?'.$flag_link['query']['token'];
}
print l(t('SAVE '), 'user/login' , array('query'=> array('destination' => $flag_url)));
print l(t('LIST'), 'user/login' , array('query'=> array('destination' => $flag_url)));
} else {
print render($content['links']['flag']);
}
By using this code, anonymous user can redirect to login page but not to last visited page.