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!