Dear Monks,

This is what I want to do:

1. set cookies
2. get cookies
3. get MySQL data based on cookie (i.e. SELECT name WHERE id=$cookie) using a config file for the username and password
4. set a new cookie using MySQL data

So if anyone knows of a script that will do this will you please let me know.

I have managed to set/get the cookies but I cannot seem to access the database. I've tried every script --below is he latest. I keep getting this error:

MyApp.pm did not return a true value at myapp.cgi line 10. BEGIN failed--compilation aborted at myapp.cgi line 10.
/htmlx/myapp.cgi
/htmlx/purge_old_sessions.cgi
/pc/modules/MyApp.pm
/pc/config/pc.cfg

myapp.cgi
#!/usr/bin/perl -w -T my $HOME_DIR; BEGIN { '/home/somename/public_html/pc'; } use strict; use lib '/home/somename/public_html/pc/modules'; # this is where I pu +t MyApp.pm use lib '/home/somename/perl/usr/lib/perl5/site_perl/5.8.8'; # this is + where I installed Perl modules use CGI::Carp qw(fatalsToBrowser); use MyApp; MyApp->new( ,-config_file => '/home/somename/public_html/pc/config/pc.cfg' )->run;
pc.cfg
user the_username password the_password dsn dbi:mysql:database=somename_database:host=localhost cgi_session_dsn driver:mysql;serializer:Storable cookie_path /
MyApp.pm
package MyApp; use strict; use base 'CGI::Application'; use CGI::Application::Plugin::AutoRunmode; use CGI::Application::Plugin::Config::Simple; use CGI::Application::Plugin::DBH (qw/dbh_config dbh/); use CGI::Application::Plugin::Session; sub cgiapp_init { my ($self, %params) = @_; # -- config $self->config_file($params{-config_file}); $self->dbh_config( $self->config_param('dsn') ,$self->config_param('user') ,$self->config_param('password') ); # -- session $self->session_config( CGI_SESSION_OPTIONS => [ $self->config_param('cgi_session_dsn') ,$self->query ,{Handle=>$self->dbh} ], DEFAULT_EXPIRY => '+31d', # should this match -expires b +elow? TBD COOKIE_PARAMS => { -expires => '+31d' ,-path => $self->config_param('cookie_path') } ); } sub terminate { my $self = shift; $self->session->flush if $self->session_loaded; # CGI::Sesssion documentation says "auto-flushing can be unreliable +. # ...regard it as mandatory that sessions always need to be explici +tly # flushed before the program exits... sub teardown() would be the # appropriate place to do this. } sub display_form : StartRunmode { my $self = shift; my $q = $self->query; my $session_data = $self->session->param('stuff') || 1; my $result = $q->start_html(-title => 'Client Login') . $q->start_form . 'First Name: ' . $q->textfield(-name=>'firstName') . $q->br . $q->submit . $q->hidden(-name =>'rm', -value => 'page_2') . $q->end_form . $q->br . $session_data . $q->end_html ; $session_data++; # reload the page to see the value change above $self->session->param(stuff=>$session_data); return $result; }
Please help!

In reply to Accessing DB by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.