You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Charlie Smith <Sm...@ldschurch.org> on 2004/06/29 18:43:01 UTC
[mp1] session variables - how to use?
What is recommended way to get/set session variables? Is there a recommended
package to use with
examples please?
Currently am using Apache/1.3.28 (Unix) mod_perl/1.28 PHP/4.3.1 mod_ssl/2.8.15
OpenSSL/0.9.7d
but plan on moving to Apache 2 at some time.
Charlie ;)
"Postmaster" made the following annotations.
------------------------------------------------------------------------------
This message may contain confidential information, and is intended only for
the use of the individual(s) to whom it is addressed.
==============================================================================
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
RE: [mp1] session variables - how to use?
Posted by Clayton Cottingham <dr...@telus.net>.
here is a test script i created to understand the basics, everyone feel free
to rip it apart, through mistakes we learn
:)
<<<:code:>>>
#!/usr/bin/perl
use strict;
use Apache::Session::MySQL;
use CGI;
=cut
SYNOPSIS
#make a fresh session for a first-time visitor
tie %session, 'Apache::Session::MySQL';
#stick some stuff in it
$session{visa_number} = "1234 5678 9876 5432";
#get the session id for later use
my $id = $session{_session_id};
#get the session data back out again during some other request
my %session;
tie %session, 'Apache::Session::MySQL', $id;
&validate($session{visa_number});
#delete a session from the object store permanently
tied(%session)->delete;
=cut
my $driver="mysql";
my $dbname="session";
my $host="127.0.0.1";
my $user="user";
my $password="password";
my $dbh = DBI->connect(
"dbi:$driver(PrintError=>1,RaiseError=>1,Taint=>1):dbname=$dbname;host=$host
", $user, $password ) or die $!;
my $q=CGI->new;
my $id=$q->param('get_id');
my $visa_number=$q->param('visa_number');
tie my %hash, 'Apache::Session::MySQL',$id , {Handle =>
$dbh,LockHandle=>$dbh};
if (!$id && $visa_number){
$hash{visa_number}=$visa_number;
}
$dbh->disconnect;
use Data::Dumper;
print Data::Dumper->Dump([%hash]);
<<<:code:>>>
i dont know if this is too relevant but i posted this on perlmonks.org:
http://www.perlmonks.org/index.pl?node_id=292469
this node contains a bit of instruction on how to check for expired sessions
using CGI::Session
> -----Original Message-----
> From: Charlie Smith [mailto:SmithCW@ldschurch.org]
> Sent: Tuesday, June 29, 2004 9:43 AM
> To: modperl@perl.apache.org
> Subject: [mp1] session variables - how to use?
>
>
> What is recommended way to get/set session variables? Is there a
> recommended
> package to use with
> examples please?
>
>
> Currently am using Apache/1.3.28 (Unix) mod_perl/1.28 PHP/4.3.1
> mod_ssl/2.8.15
> OpenSSL/0.9.7d
> but plan on moving to Apache 2 at some time.
>
> Charlie ;)
>
> "Postmaster" made the following annotations.
> ------------------------------------------------------------------
> ------------
> This message may contain confidential information, and is
> intended only for
> the use of the individual(s) to whom it is addressed.
> ==================================================================
> ============
>
>
> --
> Report problems: http://perl.apache.org/bugs/
> Mail list info: http://perl.apache.org/maillist/modperl.html
> List etiquette: http://perl.apache.org/maillist/email-etiquette.html
>
>
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html