#!/usr/bin/perl -w use DBI; use CGI::Session; use CGI; my $db_name="aa"; my $db_host="bb"; my $db_user="cc"; my $db_pass="dd"; print "Content-Type: text/html\n\n"; $dbh = DBI->connect("DBI:mysql:database=$db_name; host=$db_host", "$db_user","$db_pass", {PrintError => 1, RaiseError => 1, AutoCommit => 1}); my $cgi = new CGI; my $sid = $cgi->cookie('SessionId') || $cgi->param('SessionId') || undef; my $session = new CGI::Session("driver:MySQL;
id:MD5", undef, {Handle=>$dbh}); print "session : $session "; if ( $session->is_expired ) { print "Your session is expired. Please Login"; } else { print "Session is not expired"; } if (!$sid) { print "No Session Exists. Please Login"; } #Active Session; if ($session_user && $session_pass) { print "Username and Password are present"; } elsif (!$session_user || !$session_pass) { #Account Error. Username or Password not present. Please Login } $session->expire(1800); print "Session ID : $session->id "; $cookie = $cgi->cookie(SessionId => $session->id ); print $cgi->header(-cookie=>$cookie); $x=$cgi->cookie('SessionId'); $session->param('username', "myname"); $y=$session->param('username'); print "From Session : $y"; $name=$session->param('SessionId'); print "Value from Session : $x "; $session->save_param(); $dbh->disconnect(); print "
"; print "
"; exit;