mnlight has asked for the wisdom of the Perl Monks concerning the following question:

I am very new to perl programming and need a lot of help. I am going to tell you what I want to accomplish and you tell me what would be the best way to do it. I will try not to be long winded.

I manage my sons Hockey team web site. We need for people to volunteer for a fundraiser every weekend in the summer. I want the parents to sign up (only the parents) so I want to give them a login and password. this will be verified by with the Password table. The login will be their players name and they will identify themselves as either the Father or mother (no other choices). From that information I will query the roster table and get the parents name. The parents name will be saved so that when they get to the volunteer page all they have to do is select the available date and the Parents name will be inserted into the Volunteer table and that parent will be responsible for that date. What I am trying to do is create that login page. The information needed is the names of the players in a list he is my code to create the scrolling list.

#Volunteer.pl - Sign up sheet for Volunteers use strict; use DBI; use CGI qw(:standard); my ($dbh, $sth, $count, $query); my @val= (); my $data= (); my @date=(); $dbh = DBI->connect ("DBI:mysql:host=localhost;database=<database name +>", "mnlight","<password>", {PrintError=> 0, RaiseError=> 1}); $sth = $dbh->prepare ("select Player from Roster order by Player"); $sth->execute (); while (my @player = $sth->fetchrow_array ()) { print $query->header('MNLIGHTNING Login Form'); print $query->start_html(-title => 'Password'); print $query->start_multipart_form('POST','/cgi-bin/Password.pl'), print $query->scrolling_list( -name =>'Player', -value =>\@player, -size =>'20');

Edit Masem 2001-12-20 - CODE tags instead of BR's

Replies are listed 'Best First'.
Re: Creating a login page
by xunker (Beadle) on Dec 21, 2001 at 03:29 UTC

    A point with regard to your form generation:

    The CGI::header function (e.g. $query->header()) is what is responsible for spitting out the "content-type: text/html" things, not the page title. The standard way of using the Header function is:

    print $query->header();

    ...it will send "text/html" if nothing is specified, or you can send your own content headers by "$query->header ('image/gif')" to send a GIF image header, etc.

    As for the login process, what you'll probably want to do is have the form contain the players names list, a pair of radio buttons to select mother or father and the name of the parental in qestion and verify them all in one fell swoop, whereupon you'll probably want to assign them a cookie (with CGI::Cookie or somesuch) so they only have to do this once; if they come to this page but they've already had a cookie assigned (i.e. they've loged in before) you can send a "$query->redirect ()" to send them onward automatically.

      So what does this error mean.

      Can't call method "header" on an undefined value at Password.pl line 22.

      1 #Volunteer.pl - Sign up sheet for Volunteers 2 3 use strict; 4 use DBI; 5 use CGI qw(:standard); 6 7 my ($dbh, $sth, $query); 8 my @player = (); 9 10 11 $dbh = DBI->connect ("DBI:mysql:host=localhost;database=<datab +ase>", 12 "mnlight","<paswword>", 13 {PrintError=> 0, RaiseError=> 1}); 14 15 $sth = $dbh->prepare ("select Player from Roster order by Play +er"); 16 $sth->execute (); 17 18 while (my @row = $sth->fetchrow_array ()) 19 { 20 push @player, $row[0]; 21 22 print $query->header(); 23 print $query->start_html(-title => 'Password');

      Edit kudra, 2001-12-22 Replaced br with code

        As japh said, you forgot the line:

        my $query = CGI::new;
        which generates a CGI object stored in $query. From then on, you can call methods (header() and such) on the object, while the object knows it's a CGI object (package CGI, and thus knows to find those methods in the CGI module.

        If you forget to initialize the object, you'd be trying to call methods on an undefined value, which doesn't belong to a package, simply because it's undefined.

        perhaps you meant:

        my $cgi = new CGI; print $cgi=>header(); print $cgi->start_html(-title=>'Password');
Re: Creating a login page
by chip (Curate) on Dec 21, 2001 at 02:57 UTC
    User authentication is more a web server feature than a Perl problem. I suggest you read up on your server.

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      I am not trying to authenticate users onto the network. I am trying to exhibit some control over who volunteers for the fundraiser. I only want the names of the Parents to be entered in as volunteers so I know who to call and verify they did sign up and will you be there.

        There are issues with using a form based login, and sometimes it is more convenient to use http authentication.

        The main problem with using a form to log someone in, is that you need a way to know whether someone is logged in on an arbitrary request. There are various methods to solve this problem: you can create session ids that time out, or you can set a cookie that shows the person as logged in.

        If you utilize http authentication you can let the webserver handle keeping track of who is logged in or not. The setup for this method varies from server to server.

        If you are on an Apache server, you will need to create several files, .htaccess, .htpasswd, and .htgroup. Your .htaccess file will specify that your script requires a password to access. Your .htpasswd and .htgroup files contain information about your users. This tutorial should be enough to get you started.

        BTW, if you use this approach, you can get the username is stored as an environment variable ($ENV{REMOTE_USER}).

        Good luck with whatever approach you decide to take.


        TGI says moo

        I still think you want HTTP authentication.

            -- Chip Salzenberg, Free-Floating Agent of Chaos