sub generate {
    my $session = shift;

    my $name = $session->{args}->{ModUsertrackCookieName} || 'Apache';
    my %cookies = CGI::Cookie->fetch;
    my $value;
    if (!exists $cookies{$name} && MOD_PERL) {
        # no cookies, try to steal from notes
        require Apache;
        my $r = Apache->request;
        # %cookies = CGI::Cookie->parse($r->notes('cookie'));
        $value = $r->notes('cookie');
    } elsif (defined($cookies{$name}) && $cookies{$name}->value()) {
      $value = $cookies{$name}->value()
    }

    unless ($value) {
        # still bad luck
        require Carp;
        Carp::croak 'no cookie found. Make sure mod_usertrack is enabled.';
    }
    $session->{data}->{_session_id} = $value;
}
