Apache2-ASP

 view release on metacpan or  search on metacpan

lib/Apache2/ASP/SessionStateManager.pm  view on Meta::CPAN

  $s->context->r->err_headers_out->{'Set-Cookie'} = "$cookiename=$s->{SessionID}; path=/; $domain";
  
  # If we weren't given an HTTP cookie value, set it here.
  # This prevents subsequent calls to 'parse_session_id()' to fail:
  $ENV{HTTP_COOKIE} ||= '';
  if( $ENV{HTTP_COOKIE} !~ m/\b$cookiename\=.*?\b/ )
  {
    my @cookies = split /;/, $ENV{HTTP_COOKIE};
    push @cookies, "$cookiename=$s->{SessionID}";
    $ENV{HTTP_COOKIE} = join ';', @cookies;
  }# end if()
  
  1;
}# end write_session_cookie()


#==============================================================================
sub dbh
{
  my $s = shift;
  return $s->db_Main;
}# end dbh()


#==============================================================================
sub DESTROY
{
  my $s = shift;
  
  delete($s->{$_}) foreach keys(%$s);
}# end DESTROY()

1;# return true:

__END__

=pod

=head1 NAME

Apache2::ASP::SessionStateManager - Base class for Session State Managers.

=head1 SYNOPSIS

Within your ASP script:

  <%
    $Session->{counter}++;
    $Response->Write("You have viewed this page $Session->{counter} times.");
  %>

=head1 DESCRIPTION

The global C<$Session> object is an instance of C<Apache2::ASP::SessionStateManager>
or one of its subclasses.

It is a blessed hash that is persisted to a database.  Use it to share information across all requests for
one user.

B<NOTE:> - do not store database connections or filehandles within the C<$Session> object because they cannot be shared across
different processes or threads.

=head1 METHODS

=head2 save( )

Stores the Session object in the database.  Returns true.

=head1 CONFIGURATION

=head2 XML Config

The file C<apache2-asp-config.xml> should contain a section like the following:

  <?xml version="1.0"?>
  <config>
    ...
    <data_connections>
      ...
      <session>
        <manager>Apache2::ASP::SessionStateManager::MySQL</manager>
        <cookie_name>session-id</cookie_name>
        <cookie_domain>.example.com</cookie_domain>
        <dsn>DBI:mysql:dbname:localhost</dsn>
        <username>sa</username>
        <password>s3cr3t!</password>
        <session_timeout>30</session_timeout>
      </session>
      ...
    </data_connections>
    ...
  </config>

=head2 Database Storage

The database named in the XML config file should contain a table like the following:

  CREATE TABLE  asp_sessions (
    session_id    char(32) NOT NULL,
    session_data  blob,
    created_on    datetime default NULL,
    modified_on   datetime default NULL,
    PRIMARY KEY  (session_id)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1

=head1 BUGS

It's possible that some bugs have found their way into this release.

Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports.

=head1 HOMEPAGE

Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples
of Apache2::ASP in action.

=head1 AUTHOR

John Drago <jdrago_999@yahoo.com>

=head1 COPYRIGHT AND LICENSE



( run in 1.717 second using v1.01-cache-2.11-cpan-22024b96cdf )