"Fossies" - the Fresh Open Source Software Archive

Member "Apache-Session-1.93/lib/Apache/Session/Generate/ModUsertrack.pm" (15 Sep 2009, 2632 Bytes) of package /linux/www/Apache-Session-1.93.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ModUsertrack.pm" see the Fossies "Dox" file reference documentation.

    1 package Apache::Session::Generate::ModUsertrack;
    2 
    3 use strict;
    4 use vars qw($VERSION);
    5 $VERSION = '0.02';
    6 
    7 use CGI::Cookie;
    8 use constant MOD_PERL => exists $ENV{MOD_PERL};
    9 
   10 sub generate {
   11     my $session = shift;
   12 
   13     my $name = $session->{args}->{ModUsertrackCookieName} || 'Apache';
   14     my %cookies = CGI::Cookie->fetch;
   15 
   16     if (!exists $cookies{$name} && MOD_PERL) {
   17     # no cookies, try to steal from notes
   18     require Apache;
   19     my $r = Apache->request;
   20     %cookies = CGI::Cookie->parse($r->notes('cookie'));
   21     }
   22 
   23     unless ($cookies{$name}) {
   24     # still bad luck
   25     require Carp;
   26     Carp::croak('no cookie found. Make sure mod_usertrack is enabled.');
   27     }
   28     $session->{data}->{_session_id} = $cookies{$name}->value;
   29 }
   30 
   31 sub validate {
   32     my $session = shift;
   33 
   34     # remote_host (or remote_addr) + int
   35     $session->{data}->{_session_id} =~ /^[\d\w\.]+\.\d+$/
   36     or die "invalid session id: $session->{data}->{_session_id}";
   37 }
   38 
   39 1;
   40 __END__
   41 
   42 =head1 NAME
   43 
   44 Apache::Session::Generate::ModUsertrack - mod_usertrack for session ID generation
   45 
   46 =head1 SYNOPSIS
   47 
   48   use Apache::Session::Flex;
   49 
   50   tie %session, 'Apache::Session::Flex', $id, {
   51       Store     => 'MySQL',
   52       Lock      => 'Null',
   53       Generate  => 'ModUsertrack',
   54       Serialize => 'Storable',
   55       ModUsertrackCookieName => 'usertrack', # optional
   56   };
   57 
   58 =head1 DESCRIPTION
   59 
   60 Apache::Session::Generate::ModUsertrack enables you to use cookie
   61 tracked by mod_usertrack as session id for Apache::Session
   62 framework. This module fits well with long-term sessions, so better
   63 using RDBMS like MySQL for its storage.
   64 
   65 =head1 CONFIGURATION
   66 
   67 This module accepts one extra configuration option.
   68 
   69 =over 4
   70 
   71 =item ModUsertrackCookieName
   72 
   73 Specifies cookie name used in mod_usertrack. C<Apache> for default, so
   74 change this if you change it via C<CookieName> directive in
   75 mod_usertrack.
   76 
   77 =back
   78 
   79 =head1 LIMITATION WITHOUT MOD_PERL
   80 
   81 This module first tries to fetch named cookie, but will in vain B<ONLY
   82 WHEN> the HTTP request is the first one from specific client to the
   83 mod_usertrack enabled Apache web server. It is because if the request
   84 is for the first time, cookies are not yet baked on clients.
   85 
   86 If you run scripts under mod_perl, this module tries to steal (not yet
   87 baked) cookie from Apache request notes.
   88 
   89 See L<Apache> for details.
   90 
   91 =head1 AUTHOR
   92 
   93 Tatsuhiko Miyagawa <miyagawa@bulknews.net>
   94 
   95 This library is free software; you can redistribute it and/or modify
   96 it under the same terms as Perl itself.
   97 
   98 =head1 SEE ALSO
   99 
  100 L<Apache::Session>, L<Apache::Session::Flex>, mod_usertrack
  101 
  102 =cut