Drupal - How to display a flag to anonymous users?

You can do this in your 'node.tpl.php' by something like below, if user is logged in display flag as normal and if is not logged in redirect user to logging page with destination parameter

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_url = $flag_link['href'];
    if(isset($flag_link['query']['token'])) {
        $flag_url .= '?'.$flag_link['query']['token'];
    }
    print l(t('bookmark'), 'user/login' , array('query'=> array('destination' => $flag_url)));
} else {
    print render($content['links']['flag']);
}

To display a flag to anonymous users, refer to what's written in the community documentation of the Flag module, i.e.:

Flagging for anonymous users (even with page caching enabled). Requires Session API.

Something similar from the README.txt:

Optional Installation

1) The ability for anonymous users to flag content is provided by the Session API module, available at http://drupal.org/project/session_api.

Be aware also that Session API isn't mentioned as a dependency in the Flag module either.

Tags:

Flags

Users

7