#!/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') || und +ef; my $session = new CGI::Session("driver:MySQL;<br>id:MD5", undef, {Hand +le=>$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 "<form name=testsession method=post action='def.cgi'>"; print "<input type=submit value=submit> </form>"; exit;
Thanks in advance for any help.
Regards,
Ramesh.
Edit: g0n - code tags
In reply to How to retrive value from session using Perl CGI. by ramesh_ps1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |