Re: CGI::Session with MySQL Driver
- From: Alexandre Jaquet <alexj@xxxxxxxxxxx>
- Date: Mon, 30 May 2005 14:47:01 +0200
Mark Clements a écrit :
Alexandre Jaquet wrote:
Mark Clements a écrit :
Show us your code using param.
Does it work with the File driver?
Mark
sub login { my $username = param('user_name'); my $userpassword = param('user_password');
my ($user_name,$user_password)=sqlSelect("nom_utilisateur , mot_de_passe", "personne", "nom_utilisateur = '$username' AND
mot_de_passe='$userpassword'"); my $dir =
"C:/indigoperl/apache/htdocs/recordz/"; if ($user_name &&
$user_password) { $CGI::Session::MySQL::TABLE_NAME = 'session';
my $SESSION = new CGI::Session( "driver:MySQL", undef, { Handle =>
$dbh} ); @my_array = ("$username");
$SESSION->param("user_name", \@my_array);
open (FILE, "<$dir/myaccount.html") or die "cannot open file
$dir/myaccount.html"; print "Content-type: text/html\n\n";
$CGISESSID = $SESSION->id();
while (<FILE>) {
s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
s/\$LANG/$lang/g;
s/\$ERROR{'([\w]+)'}//g;
s/\$VINYL{'news'}/$string/g;
s/\$SESSIONID/$CGISESSID/g;
s/\$VINYL{'search'}//g;
print $_;
}
close (FILE);
}
else {
#}}
You need to learn to partition your problem. There is a load of gumpf here that gets in the way of the issue that you are having and makes it more difficult for both you and us to find a solution. You've indicated this works with the File driver, but you haven't shown us the error message or unexpected behaviour you get with the code above.
Remember to run with strict turned on - I don't think you have with the code above. Break down the code into the smallest number of lines that exhibit the behaviour you are trying to demonstrate (you have been asked to do this on other occasions). I'm not going to write the test script for you myself.
Mark
Here a complete test script :
#!perl -w use CGI qw(:standard); use Switch; use CGI::Session qw/-ip-match/; use vars qw($dbh $session); use DBI; use strict;
my $query ;
$dbh ||= sqlConnect("DBI:mysql:recordz:localhost", "alexj", "xxx");execute ();
sub execute { $query = new CGI ; my $action = $query->param('action'); if ($action) { switch ($action) { case "login" { login(); }; case "test" { }; } } }
sub login {
$session = new CGI::Session( "driver:MySQL", undef, { Handle => $dbh} );
my $username = "alexj";
$session->param("user_name", $username);
my $id = $session->id;
print "Content-type: text/html\n\n";
print "ID : $id";
}
sub sqlConnect {
my $dbname = shift || '';
my $dbusername = shift || '';
my $dbpassword = shift || ''; $dbh = DBI->connect($dbname, $dbusername, $dbpassword);
if (!$dbh) {
}
kill 9, $$ unless $dbh;
}.
- Follow-Ups:
- Re: CGI::Session with MySQL Driver
- From: Fabian Pilkowski
- Re: CGI::Session with MySQL Driver
- From: Mark Clements
- Re: CGI::Session with MySQL Driver
- References:
- CGI::Session with MySQL Driver
- From: Alexandre Jaquet
- Re: CGI::Session with MySQL Driver
- From: Fabian Pilkowski
- Re: CGI::Session with MySQL Driver
- From: Alexandre Jaquet
- Re: CGI::Session with MySQL Driver
- From: A. Sinan Unur
- Re: CGI::Session with MySQL Driver
- From: Alexandre Jaquet
- Re: CGI::Session with MySQL Driver
- From: Mark Clements
- Re: CGI::Session with MySQL Driver
- From: Alexandre Jaquet
- Re: CGI::Session with MySQL Driver
- From: Mark Clements
- Re: CGI::Session with MySQL Driver
- From: Alexandre Jaquet
- Re: CGI::Session with MySQL Driver
- From: Mark Clements
- CGI::Session with MySQL Driver
- Prev by Date: Re: Invisible variables in Perl debugger II
- Next by Date: Re: How do I ask the user for a password?
- Previous by thread: Re: CGI::Session with MySQL Driver
- Next by thread: Re: CGI::Session with MySQL Driver
- Index(es):