I don't use it, however to try to help you, I scanned the
documentation for the current CGI::Session on CPAN and this
might be of interest:
Following data source components are supported:
driver - CGI::Session driver. Available drivers are file, db_file, mysql
and sqlite.
If there is a driver for PostgreSQL, it's not mentioned.
If you need help using CGI::Session consider the mailing list. You can
ask the list by sending your questions to
(e-mail address removed) .
You can subscribe to the mailing list athttps://lists.sourceforge.net/lists/listinfo/cgi-session-user.
There's no mention of Handle or ColumnType in the documentation, that I
could see.
Post a short example. <10 lines should cover it. We don't need to
see the code from CGI::Session, only your code and what errors
you receive.
well.. the pgsql driver is a third party implementation based on
CGI::Session:
riverhttp://search.cpan.org/~sherzodr/CGI-Session-4.10/lib/CGI/Session/Dri...
Niklas, as suggested by J.G a short example ( without typos etc.. )
would be very helpfull..
i would suggest you turn on strict and warnings in this example..
Such small examples act as test cases, that help in understanding the
problem...
for eg, I did this and I see that things are working fine :
[root@deepdark gautam]# cat ./session.pl
#!/usr/bin/perl
use strict;
use warnings;
use CGI::Session;
use DBI;
my $dbh = DBI->connect("dbi
g:dbname=test;host=localhost;port=5432",
"USERNAME", "");
if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}
my $session = new CGI::Session(
"driver
ostgresql:id:md5",
undef,
{
Handle => $dbh,
ColumnType => "binary",
}
);
How can the above code work?
"driver
ostgresql:id:md5" should be "driver
ostgresql;id:md5".
Atleast as I interpret the docs...
The postgres driver is included my package.
With strict I only get loads of:
login: Global symbol "$s" requires explicit package name at ./login
line 25.
And I always has warn on.
Here's all my code:
****************************** login *************************
#!/usr/bin/perl -w
use funcs;
use Digest::SHA1 qw(sha1_base64);
#use strict;
makeHTML('register');
if(!param('user')){
print '<form name="input" action="login" method="post">
Username: <input type="text" name="user"><BR>
Password: <input type="password" name="password"><BR>
<input type="submit" value="Submit">
</form>';
}else{
$user = param('user');
$pass = param('password');
$digest = sha1_base64($pass);
$s = sqlQuerry("SELECT id, pass FROM zerus.players WHERE
name='$user'")
or die "cannot prepare";
@data = $s->fetchrow();
if($data[1] eq $digest){
print "\n<H1>You've successfully logged on</H1>\n"
} else {
print "\n<H1>Wrong password, or no user with that name</H1>
\n"
}
$s->finish or die "Cannot finnish";
}
finnishUp();
********************************** funcs.pm
************************************
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use DBI;
#use Apache::Session:
ostgres;
use DBD:
g qw
pg_types);
use CGI::Session;
use CGI::Session:
river:
ostgresql;
use CGI::Session::ID::md5;
use CGI::Session::Serialize::default;
sub openDB
{
#open db
$dbh = DBI->connect("dbi
g:dbname=zerus;host=localhost;port=5432",
"*", "*");
if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}
}
sub makeHTML
{
# Get the CGI form data
print "<HTML><TITLE>${_[0]}</TITLE><BODY bgcolor='\#000000'
text='\#aaa666'>";
}
sub sqlQuerry
{
$sth = $dbh->prepare($_[0]);
if ( !defined $sth ) {
die "Cannot prepare statement: $DBI::errstr\n";
}
$sth->execute;
$sth;
}
sub finnishUp
{
print end_html();
print $@, "<BR>\n";
if(defined($DBI)){ print $DBI::errstr, "<BR>\n"; }
eval { $dbh->disconnect; };
}
openDB;
$session = new CGI::Session("driver
ostgresql;id:md5", undef,
{Handle=>$dbh, ColumnType=>"binary"});
$CGISESSID = $session->id();
# send proper HTTP header with cookies:
print $session->header();
#$cgi = new CGI;
#print header();
*************************************************************************
If I replace all the session stuff with the commented out stuff, I get
no
errors.
This is the output:
Set-Cookie: CGISESSID=d07adf2adfd6ded310af61f101c1bed1; path=/
Date: Thu, 28 Jun 2007 23:13:37 GMT
Content-Type: text/html; charset=ISO-8859-1
<HTML><TITLE>register</TITLE><BODY bgcolor='#000000'
text='#aaa666'><form name="input" action="login" method="post">
Username: <input type="text" name="user"><BR>
Password: <input type="password" name="password"><BR>
<input type="submit" value="Submit">
</form>
</body>
</html><BR>
[Fri Jun 29 01:13:37 2007] login: (in cleanup) Can't connect to
data source '' because I can't work out what driver to use (it doesn't
seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is
not set) at /usr/share/perl5/CGI/Session/Driver/DBI.pm line 26
[Fri Jun 29 01:13:37 2007] login: (in cleanup) Can't call method
"commit" on unblessed reference at /usr/share/perl5/CGI/Session/Driver/
DBI.pm line 130 during global destruction.
*************************************************************