You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Niral Trivedi <ni...@planet.net> on 2000/06/01 16:56:44 UTC

Apache::Session

All,

I have just installed Apache::Session successfully with Apache/mod_perl
version 1.24..

I have two sample script one from example avaiable with installation
which uses 'Apache::Session::File' for session tracking and other file,
I have created from the given example but that uses
'Apache::Session::MySQL' as object store...

I have also created database called 'sessions' in which I have table
called 'sessions' which has two columns as per the perldoc. First is
'id' which is primary key and second is 'a_session'.

Now, I am successfully able to run the script and generate sessionID and
store that sessionID in MySQL database table.. But column 'a_session' is
always empty!! Following is my code.. When I ran this code first time, I
thought, I will have value of '$name' in column 'a_session' but I was
wrong!! I mean I am in impression that, in MySQL datastore we can store
all information about session for a particular sessionID. But it's not
the case.. Whereas if I run the sample example which uses
Apache::Session::File, I can see value of '$name' in the actual session
file!!! So, Can somebody clear my doubts here??

Thanks in advance..
-------------------------------------------------------------------------------------------------------
#!/usr/local/bin/perl5.00503

use strict;

use CGI;
use DBI;
use Apache::Session::MySQL;
my($query) = new CGI;
print $query->header;

#####################################
#### DB Connection ########
my($dbh) = DBI->connect("DBI:mysql:$DB",$DBUSER,$DBPASS, {
    PrintError => 1, # warn() on errors
    RaiseError => 0, # don't die on error
    AutoCommit => 1, # commit executes immediately
});
my($sessionID) = $ENV{'PATH_INFO'};
$sessionID =~ s/^\///;
$sessionID = $sessionID ? $sessionID : undef;
my %session;
my($name) = $query->param('name');

tie %session, 'Apache::Session::MySQL',$sessionID, {
    Handle => $dbh,
    LockHandle => $dbh
    };
$session{name} = $name if $name;

print "Hello<br>\n";
print "Session ID number is: $session{_session_id}<br>\n";
print "The Session ID is embedded in the URL<br>\n";
print "<br>\n";
print "Your input to the form was: $name<br>\n";
print "Your name is $session{name}<br>\n";
print "<br>\n";
print "<a
href=\"http:\/\/www.server.com/perl\/session_test\.pl\/$session{_session_id}\">Reload
this session</a><br>\n";
print "<a href=\"http:\/\/www.server.com\/perl\/session_test\.pl\">New
session</a>\n";
print "<form
action=\"http:\/\/www.server.com\/perl\/session_test\.pl\/$session{_session_id}\"
method=\"post\">\n";
print "Type in your name here:";
print "<input type=\"text\" name=\"name\"<BR>\n";
print "<input type=\"submit\" name=\"Go!\">\n";
print "</form>\n";
-------------------------------------------------------------------------------------------------------

Niral