View Single Post
Old 03-12-2003, 03:46 PM   #9
David
Administrator
 
David's Avatar
 
Join Date: Dec 2002
Posts: 609
Default

Originally posted by K Dawg

IŽve noticed you have the Download section locked untill someone has registered in the forum. I hope you know what I meen.
Can you tell me how that works? IŽll need that for my new page too.
In perl or PHP its very simple I'll use perl for this example.

Code:
#!/usr/bin/perl -w
use strict;
use DBI;
use CGI;

my $q = new CGI;

my $dbh;
eval {
$dbh = DBI->connect("DBI:mysql:database='db name';host='localhost';port='3306'",'serverUser','serverPass')
    or die "Cant connect to Db $DBI::errstr\n";
};

if ($@) { graceful_error($DBI::errstr); };

my %c = Apache::Cookie->fetch;
my $logedin_status = exists $c{bbuserid} ? $c{bbuserid}->value() : undef;
my $password = exists $c{bbpassword} ? $c{bbpassword}->value() : undef;

my $sth = $dbh->prepare("SELECT `username`, `password`, `usergroupid` FROM `user` WHERE `userid`=? AND `password`=?");

eval {
    $sth->execute($logedin_status, $password )
        or die;
};
if ($@) { graceful_error($DBI::errstr); };

my $hr_user = $sth->fetchrow_hashref('NAME_lc');

if (!$hr_user->{'username'}) {
    print $q->header;
    print "Sorry you do not have permission to access this download";
    exit(1);
} elsif ($hr_user->{'usergroupid'} == 3) {
    print $q->header;
    print "We have found a record of your account but we have received no confirmation e-mail form you";
    exit(1);
} else {
    print $q->header;
    print "Download link"
}


sub graceful_error {

    my $err = shift;

    print $q->header;
    print "ERROR: $err";
    exit(1);
}
If you need an explanation of what's doing what just ask.

David
David is offline   Reply With Quote