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

can someone tell me why I am unable to set the $name = to the appropriate value. If I set $user = to a valid user everything works fine but as soon as I set it to remote_user $name is never populated. It has worked in the past and I never changed the line other then to comment it out.
#Volunteer.pl - Insert Volunteers into database use strict; use DBI; use CGI qw(:standard); my $query = CGI::new(); my ($dbh, $sth, $sql); my @volunteer_date = $query->param("Volunteer"); my $parent = $query->param("Parent"); my $user = $query->remote_user(); #my $user = "<valid user>"; #my $name = undef; my $name = (); my $date = (); my $sub_parent = (); #my $parent = "Father"; #my @volunteer_date = ("2002-01-18"); print $query->header(), $query->start_html (-title=>'Volunteer List Form', -link=>'#FFFFFF', -vlink=>'99FF99', -alink=>'black', -style=>{'-src'=>'/CSS/stylesheet.css'} # store subparent for each parent my %parent_hash = ( 'Father' => 'Mother', 'Mother' => 'Father' ); if ( @volunteer_date ){ if (exists $parent_hash{$parent}) { my $sub_parent = $parent_hash{$parent}; for my $col ( $parent, $sub_parent ) { my $sql = "select $col from Roster where User=?"; my $sth = $dbh->selectcol_arrayref( $sql, undef, $user ); if ( @$sth && $sth->[0] ) { # any rows returned? $name = $sth->[0]; # take first one last; } } } print $query->h1({-align=>'center'},"THANK YOU FOR SIGNING UP $name"); foreach $date ( @volunteer_date ) { $sql = "select distinct Volunteer from Volunteer where Volunte +er =? and Date =?"; my $sth = $dbh->selectcol_arrayref( $sql, undef, $name, $date +); #Verify the parent is not signed up. if( @$sth ) {

Replies are listed 'Best First'.
Re: remote_user not identifing user
by dws (Chancellor) on Jan 17, 2002 at 12:30 UTC
    ... but as soon as I set it to remote_user $name is never populated.

    CGI::remote_user() simply front-ends $ENV{REMOTE_USER}, which (some?) web servers set if authentication is satisfied (i.e., a user has logged in). If the CGI is not password protected, then remote_user() should return undef.

    Is this CGI password protected?

    Have you switched web servers recently?

      It is password protected (HTTP authentication) and no I have not changed web servers ever. could it just be a problem with the hosting site?
        It is password protected (HTTP authentication) and no I have not changed web servers ever. could it just be a problem with the hosting site?

        Yes, it could be.

        As a diagnostic, try adding a simple "echo" script to dump the environment.

        #!/usr/bin/perl print "Content-type: text/html\n\n"; print "<html><body><pre>"; foreach my $key ( sort keys %ENV ) { print $key, ": ", $ENV{$key}, "<br>\n"; } print "</pre></body></html>\n";
        will get you most of the way there. If you need to supply a password to get to the script, and it doesn't display REMOTE_USER, then your provider may have changed web server settings.

Re: remote_user not identifing user
by screamingeagle (Curate) on Jan 17, 2002 at 12:36 UTC
    2 things :
    1. The page posting to your cgi page might not be sending any environment variables (there r ways to control what environment variable is sent over to the receiving page) and
    2. You might want to try accessing the %ENV hash too. for e.g.
    $name = $ENV{"REMOTE_USER"}

    try printing out all the values of the ENV hash to see whats being passed
    hth... :)
Re: remote_user not identifing user
by tadman (Prior) on Jan 17, 2002 at 20:12 UTC
    Just as a note, there are two ways to use CGI.
    1. Object-oriented mode, where you have a query object and you use it to do all your dirty work
    2. Non-object-oriented mode (i.e. procedural), where you import the functions and use them directly
    While there are presumably some perverse applications where using both methods simultaneously is advantageous, your script is not one of them. Since you are using OO mode in your code, the import parameter to use CGI is strictly unnecessary, and some would argue, "cargo cult programming". The ":standard" tag means to import the standard HTML functions. It does not mean to use "standard CGI".

    Object-Oriented:
    use CGI; my $q = new CGI; print $q->header(); my $v = $q->param('v'); # etc...
    Procedural:
    use CGI qw[ :standard ]; print header(); my $v = param('v'); # etc...
    Nary should the two be confused.