Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

poj's scratchpad

by poj (Prior)
on Jun 12, 2013 at 17:16 UTC ( #1038520=scratchpad: print w/replies, xml ) Need Help??

package module_2; use strict; use DBI; use CGI::Session; use Exporter 'import'; our @EXPORT_OK = qw( get_session ); sub get_session { my $dbh = dbh(); # delete all expired sessions CGI::Session->find( "driver:MySQL", sub{} , { Handle => $dbh } ); my $s = CGI::Session->load( "driver:MySQL", undef, { Handle => $dbh } ); if ( $s->is_empty ){ $s = $s->new(); $s->expire('10s'); # NOTE : valid for 10 seconds $s->param('B', 100); $s->param('Version', $CGI::Session::VERSION); $s->flush(); } $dbh->disconnect; return $s; } sub dbh { my $db = "dbname"; my $user = "user"; my $pw = "pw"; my $dsn = "dbi:mysql:$db:localhost:3306"; my $dbh = DBI->connect($dsn, $user, $pw, { RaiseError=>1, AutoCommit=>1 } ); return $dbh; } 1;
#/usr/bin/perl # script_1.cgi use strict; use CGI ':standard'; use Data::Dump 'pp'; use lib 'path/to/module'; use module_2 qw(get_session); my $session = get_session(); my $B = $session->param('B'); # set B for script_2 $session->param('B', $B+300); $session->flush(); print $session->header(),start_html(), h1('Script 1'),h2("\$B = $B"), a( {href=>"script_2.cgi?"}, "goto script_2"), pre( pp $session->{_DATA} ), end_html;
#/usr/bin/perl # script_2.cgi use strict; use CGI ':standard'; use Data::Dump 'pp'; use lib 'C:\inetpub\wwwroot\test'; use module_2 qw(get_session); my $session = get_session(); my $B = $session->param('B'); print $session->header(),start_html, h1('Script 2'),h2("\$B = $B"), a( {href=>"script_1.cgi"}, "go back to script_1"), pre( pp $session->{_DATA} ), end_html;
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
erix just did a 12 km-run. Slow, but unstoppable!

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2017-05-24 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?