package Checkuser; use strict; # Module export stuff BEGIN { use Exporter (); use vars qw(@ISA @EXPORT); @ISA=qw(Exporter); @EXPORT=qw( check_member check_cookie getuserinfo new ); } #use DB_Manage; sub check_cookie { my($this,$cgi,$username1,$password1)=@_; #my($username,$password)=undef; if($username1 eq "1"){ $username1=""; } else{ $username1=$cgi->param('username') } if($password1 eq "1"){ $password1=""; } else{ $password1=$cgi->param('password') } $username1=~ s/(\s+)$//; $username1=~ s/^(\s+)//; $password1=~ s/(\s+)$//; $password1=~ s/^(\s+)//; use CGI::Cookie; if ($username1 ne ""){ my $cookie_username = new CGI::Cookie( -name => 'username', -value => $username1, -path => '/', -secure => '0' ); my $cookie_password = new CGI::Cookie( -name => 'password', -value => $password1, -path => '/', -secure => '0' ); print $cgi->header(-cookie=>[$cookie_username,$cookie_password], -charset=>'gb2312' ); } else { #my %cookies = fetch CGI::Cookie; #$username = $cookies{'username'}->value; #$password = $cookies{'password'}->value; $username1 = $cgi->cookie('username'); $password1 = $cgi->cookie('password'); print "Content-type: text/html\n\n"; } return($username1,$password1); } sub check_member { my ($this,$dbh,$username,$password,$tablename)=@_; my $flag=0; #my $DBM=DB_Manage->new; #my $dbh=$DBM->db_connect; $tablename="member" if($tablename eq ""); my $qu = "select username,password from $tablename where strcmp(username,'".$username."')=0 and strcmp(password,'".$password."')=0"; my $sty=$dbh->prepare($qu); $sty->execute(); my $ry=$sty->rows; if($ry > 0){ $flag=1; } return $flag; } sub getuserinfo { my($this,$dbh,$username,$field,$tablename)=@_; #my $DBM=DB_Manage->new; #my $dbh=$DBM->db_connect; $tablename="member" if($tablename eq ""); my $qu = "select $field from $tablename where strcmp(username,'".$username."')=0"; my $sty=$dbh->prepare($qu); $sty->execute(); my $hash_ref = $sty->fetchrow_hashref; my $info = $hash_ref->{$field}; return $info; } sub new { my $this={}; shift; bless $this; return $this; } 1;