Hi team, Sarvesh,
I am also working on same lines and this is the code I am using to store
user id in the session.
#!/usr/bin/perl -w
use CGI;
use CGI::Session;
use DBI;
#my $sid = $q->cookie('SessionId') || $q->param('SessionId') || undef;
my $db_name="dbname";
my $db_host="dhhost.domain.com";
my $db_user="dbuser";
my $db_pass="dbpass";
# Prepare Database connection to store session values
$dbh =
DBI->connect("DBI:mysql:database=$db_name;host=$db_host","$db_user","$db
_pass", {PrintError => 1, RaiseError => 1, AutoCommit => 1});
my $q = new CGI;
# Create new session vareable
my $session = new CGI::Session("driver:MySQL;id:MD5", undef,
{Handle=>$dbh});
$session->param(-name =>'userid',-value => 'ramesh');
$session->expire(5000);
$cookie = $q->cookie(-name =>'SessionId',-value => $session->id );
print $q->header(-cookie=>$cookie);
print $q->h3("Cookie contains : $cookie ");
print $q->start_html,
$q->start_form(-name=>'testcookie',-method=>'post',-action=>'./cookie2.c
gi'),
$q->submit(-name=>'submit',-value=>'click to go to next page'),
$q->end_form,
$q->end_html;
$dbh->disconnect();
exit;
Before starting with this, you need to create a table to hold session
data.
CREATE TABLE sessions (
id CHAR(32) NOT NULL PRIMARY KEY,
a_session TEXT NOT NULL
);
Well, I am successful only till here and able to verify the data stored
in table.
But having problem while retrieving information from session in the
following pages.
I have session id stored in the cookie and able to get session ID from
cookie in the
next page. But failing to open the session and retrieve the stored data.
Let me know if you are able to dig further.
Regards,
Ramesh.
________________________________
From: perl-beginner%40yahoogroups.com">perl-beginner
yahoogroups.com
[mailto: perl-beginner%40yahoogroups.com">perl-beginner
yahoogroups.com] On Behalf Of sarveshjangid
Sent: Friday, September 07, 2007 8:28 PM
To: perl-beginner%40yahoogroups.com">perl-beginner
yahoogroups.com
Subject: [PBML] creating Sessions
Dear all,
I have prepared one small application in cgi perl.
I want to use login, logout etc through mysql. although i am able to
authenticate the user but don't know how to maintain sessions .
Please help.
thanking in anticipation.
...
sarvesh
NB: I am a newbee to cgi and perl
Ramesh Polepalli
mFormation Technologies Inc.
Direct Line: +91 80 6620 5939
Switchboard: +91 80 6620 5900
http://www.mformation.com
Visit WWW.MFORMATION.COM and see how the MFORMATION SERVICE MANAGER can help you to transform your business.
[Non-text portions of this message have been removed]
.